jQuery ajax success error

后端 未结 3 1610
闹比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: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

提交回复
热议问题