【发布时间】:2017-05-11 08:29:38
【问题描述】:
我知道有很多关于这个的问题,但很抱歉我真的对这个错误感到困惑......
我创建了一个登录页面,并使用 ajax 进行 POST 请求。当我使用它时会发生什么
$.ajax({
url:'../ajax/checklogin.php',
type:'POST',
dataType:'JSON',
data:$('form').serialize(),
success: function(result){
$.post("../www/login.php",{ users_id: JSON.parse(result.users_id)}).done(window.location.href='../www/index.php');
}
});
$.post 正在工作,但是当我尝试添加另一个字段来解析时,我得到了这个错误.. 错误出现在 users_active.. 出于某种原因,我不知道为什么会出现错误
$.post("../www/login.php",{ users_id: JSON.parse(result.users_id),users_active: JSON.parse(result.users_active)}).done(window.location.href='../www/index.php');
其他字段很好,但唯一给我错误的字段是 users_active.. 我什至检查了返回的 json 数组,它们是有效的 json...
【问题讨论】:
-
为什么是
JSON.parse()?result应该已经是一个对象了 -
我使用 parse 的原因是删除 " " 使其成为字符串..
-
如果我控制台
console.log(JSON.parse(result.users_active));我得到了错误标题,但是当我控制台console.log(JSON.parse(result.users_id));而不是得到"12345"时的users_id 结果是12345这就是我使用解析删除的原因" " 使其成为纯字符串。 -
你能告诉我们
result的内容吗? (console.log(result);) -
{"id":"26","users_id":"201710001","users_username":"123","users_active":"active"}这是console.log的结果,我刚刚删除了一些字段
标签: javascript jquery json ajax