$.ajax / $.post not working?

$.ajax / $.post not working?

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:
  1. <div id="the_login_form" style="display: inline;">
  2. <form id="login_form" action="">
  3. Username: <input type="text" size="10" maxlength="15" id="form_user_name" name="username" value="" />&nbsp;&nbsp;Password: <input type="password" size="10" maxlength="15" id="form_user_password"  name="password"  value="" />&nbsp;<input type="submit" value="Submit" />
  4. </form>
  5. </div>
In the <head> tags of page I have the following code:
  1. $(document).ready(function() {
  2. $('#login_form').submit(function() {
  3. $.ajax ({
  4.   type: "POST",
  5.   url: "gui/login.php",
  6.   data: $(this).serialize(),
  7.   dataType: 'xml',
  8.   success: function(data) {
  9.    alert("Returned info: "+data)
  10.   }
  11. });

  12. return false;
  13. });
  14. });
No my login.php file looks like this:
  1. <?php
  2. // Start session
  3. session_start();

  4. if (empty($_POST)) {
  5. $_SESSION['login_error'] = 'You must enter a value first!';
  6. // header('Location:'.$_SERVER['PHP_SELF']);
  7. echo '<result>'.$_SESSION['login_error'].'/<result>';
  8. } else {
  9. echo '<result>hello</result>';
  10. }
  11. ?>