我使用AJAX来获取JSON数据。用户填写带有一些地址的表单,这些地址使用AJAX发布。根据状态,响应可以是"status": "fail"
,"status": "unknown"
或"status": "success"
+许多其他内容。每个状态都应该导致新页面加载响应的其余部分。
我的问题是将数据转移到新页面。
$.ajax({
url:"https://domain.local/",
type:"POST",
crossDomain: true,
dataType: "json",
data : data,
headers: {
'Content-Type': "application/json; charset=utf-8"
},
success: function(data) {
if (data.result.Status == " fail ") {
// head to fail.php and show response
}
else if (data.result.Status == " unknown ") {
// head to unknown.php and show response
}
else if (data.result.Status == " success ") {
// head to succes.php and show response
}
}
});
有谁知道怎么做?
答案 0 :(得分:1)
答案 1 :(得分:1)
使用Cookie :
http://www.w3schools.com/js/js_cookies.asp
将自己的属性附加到Window对象:
http://www.w3schools.com/jsref/obj_window.asp
if (data.result.Status == " fail ") {
window.myOwnData = data;
window.location.href = "fail.php";
}
将您的数据作为重定向网址的GET参数
传递if (data.result.Status == " fail ") {
window.location.href = "fail.php?someData=" + data + "&someOtherData=" + otherData ;
}
修改强>
或使用 JSSession ,在此讨论:Persist javascript variables across pages?
我想还有更多的选择
答案 2 :(得分:1)
您可以使用window.location.href
指定要重定向的页面
if (data.result.Status == " fail ") {
window.location.href = "http://xyz.com/fail.php";
}
else if (data.result.Status == " unknown ") {
window.location.href = "http://xyz.com/unknown.php";
}
else if (data.result.Status == " success ") {
window.location.href = "http://xyz.com/success.php";
}