jQuery ajax success error

后端 未结 3 1599
闹比i
闹比i 2021-02-19 03:02

I\'m trying to submit a form witch sends an email:

JS

var that = $(this);
$.ajax({
  url: \'../wp-content/themes/bsj/php/validate.php\',         


        
相关标签:
3条回答
  • 2021-02-19 03:04

    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

    0 讨论(0)
  • 2021-02-19 03:12

    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

    0 讨论(0)
  • 2021-02-19 03:14

    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.

    0 讨论(0)
提交回复
热议问题