how to redirect the page to specific url who we obtain from response [get by sending ajax request]
my javascript code send a request and get the ID who created by user and unique. now i want to show detailed of using ID.
the ID i obtain through ajax request. tell me why this code not wait for response and gone without running whole statement i passed using if else condition
$.ajax({
url: "/home/ajax",
global: false,
type: "POST",
data: ({ fname: fname, mname: mname, lname: lname, phone: phone, land: land, address: add, district: dist, city: city, state: state, pincode: pincode }),
dataType: "json",
开发者_JS百科 async: false,
success: function (data) {
if (data.result) {
var groupID = data.groupID;
document.location = "home/ajax_add/" + groupID;
}
else
$("#errorgroup").append(data.message);
}
});
the code not wait for response and gone out from the block forget if and else who i write on them.
how i can do something then they wait for id and redirect the page i specify in code.
In syncronous mode you don't have method.
change it as follow:
var myResponse = $.ajax({
url: "/home/ajax",
global: false,
type: "POST",
data: ({ fname: fname, mname: mname, lname: lname, phone: phone, land: land, address: add, district: dist, city: city, state: state, pincode: pincode }),
dataType: "json",
async: false
});
Then you manage your response variable (myResponse) as you want.
精彩评论