I am currently creating a website. The issue I am stuck is I cannot redirect to another ASPX page using Javascript. Here goes my code:
<asp:Button ID="Save" runat="server" Text="Schedule" CssClass="vs-btn mT10" OnClientClick="return SendFormValuesForXml(); return false;" />
The above Javascript function performs an AJAX call and upon success I redirect to another page where several things are being performed. AJAX call goes here:
var responseString = "";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/MakeXml",
dataType: "json",
data: "{'data':'" + stringToSend + "'}",
async: false,
cache: false,
success: function (result) {
debugger;
window.location.reload(true);
var valuationUrl = window.location.protocol + "//" + window.location.host + "/ValuationList.aspx";
window.location.assign(valuationUrl);
return false;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
Now everything is happening correctly, except the redirection in the success function. Any idea what is interfering with the javascript? Additional information:
- No update panel is working on the page, or any other page of the website.
- No error is thrown by the browser except the bad Chrome 'jquery.min.map' not found error.
What I have so far tried:
- document.location.replace(valuationUrl);
- location.href = valuationUrl;
- $(location).attr('href', valuationUrl);
And all other options that are mentioned on stack overflow's this link.
Update: Bad Solution I adopted After doing a lot of things, like taking a non-visible button and running the server side function on its Click to redirect page and other things, all of them failed. What I did is I set a hidden field with 0, and then update its value to 1. Later when the same page loads, I checks if its value is 1, so I force redirection to the next page.
window.location.href = "/valuationlist.aspx". You don't need to do any of that protocol stuff.reload()?var valuationUrl = window.location.protocol + "//" + window.location.host + "/ValuationList.aspx";I did this so that when the website goes live, it can have HTTP or HTTPS, and any URL / Host.