[英]JQuery function suddenly stopped working with error converting Javascript argument
about a year ago I wrote a JQuery/Javascript script which makes an ajax call to a PHP page to change a user password, and it has been working wonderfully ever since. 大约一年前,我编写了一个JQuery / Javascript脚本,该脚本对PHP页面进行了ajax调用以更改用户密码,并且自此以来,它的运行一直非常出色。 Earlier today I started getting complaints that the ajax call is no longer working.
今天早些时候,我开始抱怨ajax调用不再起作用。 When I go to submit the password change form I get the following error:
当我提交密码更改表时,出现以下错误:
Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild] http://www.site.com/js/jquery-1.4.4.min.js Line 124
无法转换JavaScript参数arg 0 [nsIDOMDocumentFragment.appendChild] http://www.site.com/js/jquery-1.4.4.min.js第124行
Even though this error occurs, the user's password is changed, and the ouput from the PHP is exactly as it should be... a properly formatted json string: 即使发生此错误,用户的密码也会更改,PHP的输出也应该与它的输出完全一样。一个格式正确的json字符串:
{"Authenticated":{"0":"false"},"MessageString":{"0":"Your User Password Was Changed Successfully."},"PasswordChanged":{"0":"true"}}
None of the files associated with this project have been changed in several months, and this form gets used at least a few times a day, so I'm not sure why it suddenly stopped working. 与该项目关联的文件在几个月后都没有更改,并且该表单每天至少使用几次,因此我不确定为什么它突然停止工作。
Here is the script I am running, and I am running it with JQuery 1.4.4: 这是我正在运行的脚本,并且正在与JQuery 1.4.4一起运行:
function makePasswordRequest() {
email = jQuery("#email").val();
currentPassword = jQuery("#currentPassword").val();
newPassword = jQuery("#newPassword").val();
newPasswordRetype = jQuery("#newPasswordRetype").val();
jQuery.post("../changeUserPassword.php", {
email: email,
currentPassword: currentPassword,
newPassword: newPassword,
newPasswordRetype: newPasswordRetype
},
function(data){
if(data.PasswordChanged[0] == true || data.PasswordChanged[0] == "true"){
jQuery("#notificationArea").removeClass("failure");
jQuery("#notificationArea").addClass("success");
}
else{
jQuery("#notificationArea").removeClass("success");
jQuery("#notificationArea").addClass("failure");
}
jQuery("#notificationArea").html(data.MessageString);
}, "json");
};
function resetPasswordRequest() {
email = jQuery("#email2").val();
jQuery.post("../resetUserPassword.php", {
email: email,
},
function(data){
if(data.PasswordChanged[0] == true || data.PasswordChanged[0] == "true"){
jQuery("#notificationArea2").removeClass("failure");
jQuery("#notificationArea2").addClass("success");
}
else{
jQuery("#notificationArea2").removeClass("success");
jQuery("#notificationArea2").addClass("failure");
}
jQuery("#notificationArea2").html(data.MessageString);
}, "json");
};
jQuery(document).ready(function(){
jQuery("#passwordChangeForm").submit(function(e){
e.preventDefault();
makePasswordRequest();
});
jQuery("#passwordResetForm").submit(function(e){
e.preventDefault();
resetPasswordRequest();
});
});
I can't figure out what the problem is, especially since this has been working well for the last year. 我无法弄清楚问题出在哪里,尤其是自从去年以来,它一直运行良好。 Any help would be greatly appreciated!
任何帮助将不胜感激!
I don't know if this would be a problem, but when you're setting the inner HTML of the one element with: 我不知道这是否会有问题,但是当您使用以下方法设置一个元素的内部HTML时:
jQuery("#notificationArea").html(data.MessageString);
data.MessageString is {"0":"Your User Password Was Changed Successfully."}, so I wonder if that could be a problem? data.MessageString为{“ 0”:“您的用户密码已成功更改。”},所以我想知道这是否可能是个问题? Wouldn't you want data.MessageString[0]?
您不需要data.MessageString [0]吗?
Im pretty sure the problem lies in jquery not detecting it's JSON and not converting JSON properly. 我很确定问题出在jquery中,它无法检测到JSON并且无法正确转换JSON。 Try sending the proper headers right before the output.
尝试在输出之前发送正确的标头。
header('Content-Type: application/json');
What must have changed is your server's config. 必须更改的是您服务器的配置。 Which doesn't really depend on you
哪一个不完全取决于您
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.