我有这个功能:
function formSubmitted(json, grandTotal) {
$.ajax({
type: "POST",
url: "../quotes/create",
data: {
quote: {
name: json.name,
json: JSON.stringify(json),
email: json.email,
uid: json.id,
grand_total: grandTotal,
postcode: json.postcode,
}
},
dataType:'text',
success: function(data,status,xhr){
console.log(status);
alert("AWESOME!");
window.location.assign("http://www.example.com/thanks?id=json.id")
},
error: function(xhr,status,error){
console.log(status,error);
alert("ERROR!");
}
});
}
一切正常,但是我想做的就是成功使用window.location重定向:
http://www.example.com/thanks?id=json.id
json.id与
uid: json.id,
在上面的代码中。我需要做些什么才能使这项工作?
最佳答案
function formSubmitted(json, grandTotal) {
$.ajax({
type: "POST",
url: "../quotes/create",
data: {
quote: {
name: json.name,
json: JSON.stringify(json),
email: json.email,
uid: json.id,
grand_total: grandTotal,
postcode: json.postcode,
}
},
dataType:'text',
success: function(data,status,xhr){
console.log(status);
alert("AWESOME!");
window.location.assign("http://www.example.com/thanks?id=" + json.id)
},
error: function(xhr,status,error){
console.log(status,error);
alert("ERROR!");
}
});
}
关于javascript - 在函数中访问JavaScript数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26658812/