I have an ajax call in my JavaScript code which receives a GUID in the response from server side code. On the success method it uses that GUID to call an iframe and then after that call is done, it is supposed to refresh the page.
What I see in fiddler is that the iframe session is getting aborted. My only guess is that it is getting aborted by the browser when forced to refresh: if I remove the refresh part, the iframe session sends the request and receives the response successfully.
How can I make the page refresh when the iframe has finished its job? Someone suggested that I use the promise, but I tried $.Deferred()
in jQuery and still wasn't successful. I think I am not using the $.Deferred()
method correctly.
Note: it works if I set ajax to call in sync manner but I am hoping to find a better solution.
Here is what I have in code:
foo() {
this.$link.click((e) => {
e.preventDefault();
$.ajax({
url: "/serverEndpoint",
type: "POST",
success: (id) => {
this.iframeCall(id);
window.location.href = window.location.origin;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
});
}
iframeCall(id) {
var iframe = document.createElement('IFRAME');
iframe.setAttribute("src", someUrl+id);
iframe.style.display = 'none';
document.body.appendChild(iframe);
}