I\'m trying to submit a form witch sends an email:
JS
var that = $(this);
$.ajax({
url: \'../wp-content/themes/bsj/php/validate.php\',
I had the same problem;
textStatus = 'error'
errorThrown = (empty)
xhr.status = 0
That fits my problem exactly. It turns out that when I was loading the HTML-page from my own computer this problem existed, but when I loaded the HTML-page from my webserver it went alright. Then I tried to upload it to another domain, and again the same error occoured. Seems to be a cross-domain problem. (in my case at least)
I have tried calling it this way also:
var request = $.ajax({
url: "http://crossdomain.url.net/somefile.php", dataType: "text",
crossDomain: true,
xhrFields: {
withCredentials: true
}
});
but without success.
This post solved it for me: jQuery AJAX cross domain
You did not provide your validate.php
code so I'm confused. You have to pass the data in JSON Format when when mail is success.
You can use json_encode(); PHP function for that.
Add json_encdoe
in validate.php in last
mail($to, $subject, $message, $headers);
echo json_encode(array('success'=>'true'));
JS Code
success: function(data){
if(data.success == true){
alert('success');
}
Hope it works
Try to set response dataType property directly:
dataType: 'text'
and put
die('');
in the end of your php file. You've got error callback cause jquery cannot parse your response. In anyway, you may use a "complete:" callback, just to make sure your request has been processed.