我正在使用php/ajax提交一个没有页面刷新的表单。这是我的档案-
Coupon JS
jQuery(document).ready(function(){
jQuery(".appnitro").submit( function(e) {
$.ajax({
url : "sms.php",
type : "post",
dataType: "json",
data : $(this).serialize(),
success : function( data ) {
for(var id in data) {
jQuery('#' + id).html( data[id] );
}
}
});
//return false or
e.preventDefault();
});
});
SMS.PHP
<?php
//process form
$res = "Message successfully delivered";
$arr = array( 'mess' => $res );
echo json_encode( $arr );//end sms processing
unset ($_POST);
?>
这是我的HTML页面代码-
<form id="smsform" class="appnitro" action="sms.php" method="post">
...
</form>
<div id="mess" style="background:green;"></div>
现在不是通过Ajax提交表单而不刷新页面,而是将页面重定向到
baseurl/sms.php
页面上唯一可见的是
{"mess":"Message successfully delivered"}
我猜PHP脚本没有成功返回jquery,因此会显示sms.php最后一部分中的echo。
如何使PHP脚本成功返回?
关于如何调试这个的任何想法。我尝试使用
return false
在coupon.js的末尾,但没有结果。
当我点击提交时,Firebug给出了以下结果-
POST http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php
404 Not Found 1.29s `jquery.min.js (line 130)`
响应
Firebug needs to POST to the server to get this information for url:
http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php
This second POST can interfere with some sites. If you want to send the POST again, open a new tab in Firefox, use URL 'about:config', set boolean value 'extensions.firebug.allowDoublePost' to true
This value is reset every time you restart Firefox This problem will disappear when https://bugzilla.mozilla.org/show_bug.cgi?id=430155 is shipped