I am trying something that should be simple. My main.html page contains a form, use jQuery to AJAX post the form and return the result of that post.
However, each time I try the submit, using either $.ajax or $.post, the resulting "alert()" returns my entire main.html HTML document, and nothing at all from the login.php file? I use Firefox's Firebug to trap errors/exceptions, but nothing?
Hopefully someone can shed some light on this for me, my code is below.
P.S. I'm using jquery-1.3.2.js
Many thanks, J.
I have a form in my main.html page like so:
- <div id="the_login_form" style="display: inline;">
- <form id="login_form" action="">
- Username: <input type="text" size="10" maxlength="15" id="form_user_name" name="username" value="" /> Password: <input type="password" size="10" maxlength="15" id="form_user_password" name="password" value="" /> <input type="submit" value="Submit" />
- </form>
- </div>
In the <head> tags of page I have the following code:
- $(document).ready(function() {
- $('#login_form').submit(function() {
- $.ajax ({
- type: "POST",
- url: "gui/login.php",
- data: $(this).serialize(),
- dataType: 'xml',
- success: function(data) {
- alert("Returned info: "+data)
- }
- });
- return false;
- });
- });
No my login.php file looks like this:
- <?php
- // Start session
- session_start();
- if (empty($_POST)) {
- $_SESSION['login_error'] = 'You must enter a value first!';
- // header('Location:'.$_SERVER['PHP_SELF']);
- echo '<result>'.$_SESSION['login_error'].'/<result>';
- } else {
- echo '<result>hello</result>';
- }
- ?>