Sarvap Praharanayuthan
Sarvap Praharanayuthan

Reputation: 4360

AJAX function returns status 0

$.ajax({
   type: "POST",
   url: "check-email",
   data: {email: "[email protected]"},
   success: function(data)
   {
    // success part here        
   },
   error: function(xhr)
   {
    alert(xhr.status);
   }
});

This will call another PHP file. But the sad thing is the error part is executed always with xhr.status printing as 0. What would be the problem?

Note:
1. This works perfectly in the local.
2. Both the script, check-email page is located in the same server.
3. The server is secured with https and it is in WWW version.

Update:

error: function(jqXHR, textStatus, errorThrown)
{
  alert(textStatus, errorThrown);
}

This prints simply as "error".

Upvotes: 0

Views: 167

Answers (1)

MonkeyZeus
MonkeyZeus

Reputation: 20747

I would have done this as a comment but the code would be a nightmare.

In your PHP page write this somewhere:

<?php
echo '<pre>'.print_r($_POST, true).'</pre>';
echo '<pre>'.print_r($_GET, true).'</pre>';
?>

Now:

  1. Open up your Developer tools (Chrome) or Firebug (FireFox) and visit the Network tab.
  2. Refresh your page that makes the AJAX call
  3. Find the AJAX call to "check-email" in the Network tab and click it
  4. What do you see?
  5. Also there is a sub-tab called "Headers" in the developer tools, take a look at it

Upvotes: 1

Related Questions