gpt4 book ai didi

javascript - ajax post方法无法接收php文件中的数据

转载 作者:行者123 更新时间:2023-11-29 21:21:57 26 4
gpt4 key购买 nike

forget.php PHP:

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 控制台中检查没有错误。

调用被完美地发送到相应的文件。

最佳答案

问题是 processData 是错误的。只需完全删除此选项,它就可以工作。如果这不起作用,也请删除 contentType

有关更多信息,请阅读有关 options 的文档仔细。

processData 设置为 false 意味着以创建的形式发送数据。设置为 true,它将把它处理成一个查询字符串。

默认的内容类型 header 是application/x-www-form-urlencoded; charset=UTF-8,并将内容类型设置为 false 同样将其完全删除。

我不会修改这些默认值,除非您首先确切地知道为什么需要更改它。

关于javascript - ajax post方法无法接收php文件中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38334721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com