这是我目前的代码,它的工作范围是它找到data.success并在返回正确的值时启动下一页,我遇到的麻烦是解析一些额外的数据并传递到本地存储,所以我在下一页使用它,例如用户ID,用户名等
$.post(postTo,{email:value1 , password:value2, tag:tagvar} ,
function(data) {
//$('#output').html('inside');
if(data.success == '1') {
$.mobile.changePage( "home.html", { transition: "flip"} );
} else {
$('#output').html('Could not connect please try again');
}
},'json');
return false;
});
});
这是从请求中返回的JSON ...
{"tag":"login","success":1,"error":0,"uid":"4fc3562b9a8369.38575999","user":{"name":"test","email":"test@test.ie","created_at":"2012-05-28 11:40:43","updated_at":null,"ac":"8","user_type":"1"}}
我真的不确定如何正确解析以及如何使用本地存储。
非常感谢
答案 0 :(得分:0)
如果您想查看解析的数据,可以使用这个漂亮的在线解析器:http://json.parser.online.fr/
从那时起,您应该能够访问和保存您需要的任何内容(例如 data.user.name )。
至于将数据保存到本地存储空间,请查看该主题的W3C manual。例如:
...
if (typeof(Storage)!=="undefined") {
localStorage.username = data.user.name;
}
...