[英]when change user password in laravel by using modal, it always return false ajax?
[英]Issue using Ajax to change a user Password
我在尝试使用 Ajax 在我正在处理的网站上更改用户密码时遇到了一个奇怪的问题。 基本上,我有一个表单,用户可以输入他们的用户名、旧密码和新密码两次。 从那里 JQuery 接管并向 PHP 页面发出 Ajax 请求(我已经尝试过.post and.get 得到相同的结果)。 PHP 页面执行基本错误检查(确保填写所有字段,新密码匹配,并且新密码满足所有复杂性要求),然后使用 simplexml_load_file() 向 web 服务发出请求(用 VB 编写, 请求是通过 URL 与 urlencoded 获取参数,并返回 XML) 实际更改用户密码。
在使用不符合复杂性要求的密码发出请求时,从不调用对 web 服务的请求,并且 Ajax 请求工作正常。 在缺少表单字段的情况下发出请求时,会发生同样的事情。
通过直接访问 PHP 页面并手动键入获取参数来发出请求时,一切都按计划进行。
当我尝试使用 Ajax 使用正确的密码并填写所有字段来发出请求时,就会出现问题。 我收到以下错误:
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: path-to/jquery-1.6.2.min.js :: <TOP_LEVEL> :: line 18" data: no]
这是我的 javascript:
function makePasswordRequest() {
email = $("#email").val();
currentPassword = $("#currentPassword").val();
newPassword = $("#newPassword").val();
newPasswordRetype = $("#newPasswordRetype").val();
$.get("../changeUserPassword.php", {
"email": email,
"currentPassword": currentPassword,
"newPassword": newPassword,
"newPasswordRetype": newPasswordRetype
},
function(data){
if(data.PasswordChanged){
$("#notificationArea").addClass("success");
}
else{
$("#notificationArea").addClass("failure");
}
$("#notificationArea").html(data.MessageString);
}, "json");
};
$(document).ready(function(){
$("#passwordChangeForm").submit(function(e){
e.preventDefault();
makePasswordRequest();
});
});
有任何想法吗?
实际上我认为 JSON object 格式是这样的,名称和值都应该被引用
get("../changeUserPassword.php", {
"email": "email",
"currentPassword": "currentPassword",
"newPassword": "newPassword",
"newPasswordRetype": "newPasswordRetype"
},
好的,伙计们,我已经解决了这个问题。 The issue appears to be that the Web service was sending back some kind of object (which contained only a string), and while the JSON looked fine while accessing it directly, JavaScript couldn't parse it. 我编辑了代码以从每个类似字符串的 object 中提取索引 0 处的数据,并且一切运行良好。 感谢大家的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.