【发布时间】:2016-07-12 16:44:19
【问题描述】:
forget.phpPHP:
if (! (empty($_POST['emailforget'])) ) {
echo "here in the function";
} else {
echo "here";
}
AJAX:
$("#passreset").on('click', function(e) {
var emailforget = $("#tempemail").val();
alert(emailforget);
//ajax call here
$.ajax({
type: "post",
url: 'user/forgetpass.php',
data: {
'emailforget': emailforget
},
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
//alert("here in function beforesent");
},
success: function(html) {
//alert(html);
document.getElementById("error").innerHTML = html;
},
error: function() {
alert("alert error");
}
});
return false;
});
HTML:
<input type="email" id="tempemail" name="tempemail"
placeholder="Enter your email address" value="ab.waseem@yahoo.com" required>
代码运行良好,但突然停止工作。
在 Firefox 和 Chrome 控制台中检查没有错误。
调用完美地发送到相应的文件。
【问题讨论】:
-
使用您的开发者控制台(Chrome 或 FF)并单击“网络”选项卡,然后限制为“XHR”——这是您的 AJAX 请求。触发 AJAX 调用。检查电话 - 是 200 吗?如果是这样,服务器返回的响应是什么? (这一切都在开发者控制台中可用:developer.chrome.com/devtools)。通话是否发生?如果不是,那么您的 jQuery 是否在文档的
head中?如果是这样,则 jQuery 加载时passreset元素不存在,因此请参阅此问答:stackoverflow.com/questions/6173238/jquery-event-not-firing -
是否可以像您的 URL 指向
user/forgetpass.php而您的实际文件为forget.php一样简单? (根据您的问题元信息推断) -
@cale_b 是的 ajax 调用是 200,但它没有传递数据 ($_POST['emailforget']) 总是空的..
-
另外,如果你使用 jQuery,像这样:
document.getElementById("error").innerHTML=html;可能变成$('#error').html(html);.... -
<form>的其余部分是什么样的?
标签: javascript jquery ajax