0

I'm writing file uploader in which first POST request should be canceled if next request is about to be sent.

I must upload very big files so this situation will be quite common.

Can I cancel currently running request i requests module?

BPS
  • 1,133
  • 1
  • 17
  • 38

1 Answers1

0

The client side (the web page itself - ie: the Javascript/HTML) generally cannot directly control what happens up on the server (the processing of the POST you sent) once the POST is submitted.

Also, a traditional "form submission" POST is Synchronous, and once it is initiated you basically lose control of the webpage until it comes back with something, OR until you navigate elsewhere (such as clicking the Back button) and thus deciding not to wait around for the POST to return.

In layman's terms, I believe these are the typical limitations to how it works.

If you use Javascript and AJAX to send your post asynchronously (ie: "In the background") you do not lose control of your page and can still run javascript and do things on the page, like set a timer and take action if the post has not completed within a certain time limit.

Doing so in an intelligent fashion still takes the understanding of various basic AJAX concepts, and it's best to go learn about it and not just paste in someone's solution the first time - but this is how you go about tackling that type of problem.

Some info on Ajax Sync/Async requests

** edit: now that I Want a decent intro tutorial to link to for doing proper Ajax, I cannot find one anywhere. But anyways that's the technique you probably need, you'll probably have to search around.

recnac
  • 3,744
  • 6
  • 24
  • 46
John Fantastico
  • 332
  • 1
  • 7