Redirect To Url Taken From Json Response
I am using jquery ajax method to make http request to php webpage, and in response I am taking json like {'status':'success','url':'http url'} on success function I am redirecting
Solution 1:
I personally use
window.location.replace(url);
Read More - "The replace() method replaces the current document with a new one" window.location.replace() better simulates a http redirect
There are other various options like:
window.location.href = "http://stackoverflow.com";
Which acts as a link click
Solution 2:
have u tried window.location = "url"
url should include http://
and it should be inside quotes
Solution 3:
if you use jquery it would be easier. here's an example:
function save(){
var item = "value of some input";
$.ajax({
url : "process.php",
dataType : "json",
data : "item ="+item,
type : "POST",
cache : false,
success :
function (data){
// if the return of your json like {"status":"success","url":"http url"}
// use this
if (data.status == "success"){
window.location.href = data.url;
}
else{
alert("error occured");
}
}
});
}
Post a Comment for "Redirect To Url Taken From Json Response"