Reputation: 1417
i have been using "window.location.href" for a long time now without any issues.
the URL is calling a server process that first initiates a conversion and a download, and it usually takes just a second or two. but occasionally the server conversion/download process might take much longer. when this happens, my users see a nasty "timeout" message.
so, i am trying to determine if there is any way, possibly using the magic of jquery, something like:
$(location).attr('href',url, function() {
success: {
// success stuff
}
failure: { // failure stuff
}
});
i thought about using .ajax too, but i didnt think i would be able to have the results written to the disk using jQuery. it seemed a lot easier to stick with windows.location.href if possible.
another possibility is to figure out some way to control how long "window.location.href" is willing to wait. maybe using setTimeout() somehow ?
thank you very much.
Upvotes: 0
Views: 1230
Reputation: 4886
There's no way to handle the timeout if you are using window.location.href to trigger the request
This is how you could do your request as an ajax request with jquery:
$.get("url for request").done(function(htmlReturned) {
//do whatever you like here on success, even window.location.href
}).fail(function(jqXhr, statusText, errorThrown){
//handle failure here
});
You can also use $.post if you need to perform a post request. If you need to pass some parameters in the request you can do it this way $.get(url, {param1: "value1", param2: "value2"});
If you haven't done this before, the best resource is the ajax page from jquery documentation ($.get and $.post is just shorthand for ways of calling $.ajax).
Upvotes: 1