I am redirecting to a specific page after button click in jquery ajax success function
I have this code with me:
$.ajax({
// additional code omitted
success:function(data) {
var value = JSON.parse(data.d);
window.location.href = "https://www.example.com" + value.dataSet.Table[0].RedirectURL;
}
});
Now I am getting value of value.dataSet.Table[0].RedirectURL as "~/myPost.aspx"
So the complete url becomes : https://www.example.com/~/myPost.aspx
To avoid this I had done something like this:
var url = "https://www.example.com" + "~/myPost.aspx"
window.location.href= url.replace("~","");
But this code doesn't redirect me to new page. It stays where it is.
What should be done to remove the tilde sign (~) from the URL such that it becomes like https://www.example.com/myPost.aspx Jquery Ajax?
EDIT:
My second attempt:
I have tried to remove the first character as I have ~ only at the beginning of the URL.
function removeChar(str) {
let temp = str.split('');
return temp.slice(1).join('');
}
and then...
$.ajax({
// additional code omitted
success:function(data) {
var value = JSON.parse(data.d);
let inputURL = value.dataSet.Table[0].RedirectURL;
let outputURL = removeChar(inputURL); // this gets /myPost.aspx but it doesn't redirect after this line.
window.location.href = "http://www.example.com/" + outputURL;
}
});
Note: The value of ** value.dataSet.Table[0].RedirectURL** is ~/myPost.aspx
In this case, it is not redirecting to the desired page. The page reloads and stays where it is.