0

I am creating a small web app.

In one of the webpage in the app, part of the page is update using ajax. Ajax will retrieve the data from a java servlet on the server.

I am new to ajax (and javascript) and I don't understand some of the in's and out's of it.

Do I need to use xmlhttprequest.timeout in case the server take too long to send the response? I understand that some browsers don't support this, so is it unrelaible?

Does ajax consume data while waiting for the response from the server? I am asking this in case the server takes too long to send the response and the user is using a mobile device with data allowance limits?

I would appreciate any help on this

Edit: I am using tomcat on the backend server. How can I tell tomcat to send a 408 (server timeout), if the request/response is taking to long to process? I understand that I cannot do this in server.XML as connection timeout is only if the server has not received the request or am I wrong?

DannyR
  • 69
  • 8
  • Welcome to SO. Please visit the [help] to see what and how to ask here. HINT: Post efforts and code – mplungjan Jan 13 '16 at 10:31
  • that also can manage by your backend ... define a time in php if the process is still not finish after that time just return something .. and ask user to try again ... – Ye Lwin Soe Jan 13 '16 at 10:32
  • If you can use jQuery (recommended when using cross browser Ajax), look at http://stackoverflow.com/questions/5225597/set-timeout-for-ajax-jquery – mplungjan Jan 13 '16 at 10:32
  • @DannyR Please give us your sample code ,it is more easy to understand what's wrong with you – Willie Cheng Jan 13 '16 at 10:36
  • The server is only returning a simple text ( a word). Which would not take a long time normally. My mean concern is that if the server hangs or take a long time to send the response, will the users device consume alot of data while waiting or does it not consume data while waiting for response. – DannyR Jan 13 '16 at 10:47
  • _consume a lot of data_ ? __NO__ But Event loop will _RUN_ for it until data is received or `error` is thrown. – Rayon Jan 13 '16 at 10:57
  • Thank for the reply, does that mean that ajax does not consume data while waiting for the response? – DannyR Jan 13 '16 at 11:07

1 Answers1

1

Do I need to use xmlhttprequest.timeout in case the server take too long to send the response?

No. The browser/network stack's default timeout is usually sufficient.

Does ajax consume data while waiting for the response from the server?

It is just an HTTP request and response. It takes no more bandwidth than any other request. If no data is being transferred because the server is taking time to respond, then no data is being transferred.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335