【发布时间】:2014-10-27 14:13:42
【问题描述】:
我使用以下代码提交表单:
$.ajax({
url: $('#myForm').attr('action'),
url: 'index.php',
type: 'post',
/*dataType: 'html json', *///tell the server that you expect json
data: {
"num" : $('#myNum').val(),
},
success: function(response) {
alert(response);
if ( check_validate() == 1) {
alert(response);
}
else {}
}
});
然后在 PHP index.php 我有:
if (isset($_POST["num"])) {
$num = $_POST["num"];
if($num == 1)
echo "sure!";
}
带有sure! 和整个index.php 页面源代码的JS 弹出窗口。有没有办法删除源代码并只显示响应而不将dataType 设置为JSON?
【问题讨论】:
-
die(), exit ... 是你的朋友!
-
所以大概在你的小
if()块之后你有更多的代码/html?输出“确定!”后只需exit()。
标签: javascript php ajax json forms