By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

HTTP Request from JavaScript

P: 4
Hi,
I am trying to create and send a HTTP Request from a .js file to my server. But when I do this using the GET method and send the necessary parameters along in the URL, i have a problem. That at times the URL length goes beyond 255 characters and the request is rejected.

Then I tried the same using the HTTP POST method and using the XmlHttpRequest.send() method. The problem here is that, this method is too slow and the browser hangs if i do this in synchronous mode (xmlhttprequest.open('POST', "../MainView", false)). But this behavior is not acceptable.

So can some one suggest me an alternative to send the HTTP request, in such a manner that I can also accommodate all my parameters and it is faster than XmlHttpRequest

TIA
Harmik
Feb 6 '07 #1
Share this Question
Share on Google+
17 Replies

acoder
Expert Mod 15k+
P: 16,027
Welcome to The Scripts

Instead of using the synchronous method, use asynchronous (the A in AJAX). See this page for more info.
Feb 6 '07 #2

P: 4
Welcome to The Scripts

Instead of using the synchronous method, use asynchronous (the A in AJAX). See this page for more info.
Thanks a lot for your response. But the problem here is that I need to send the HTTP Request synchronously.

So what I would appreciate is an alternative method to send the request ...

TIA
Harmik
Feb 6 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Is there any particular reason why you must send it synchronously? It is unreliable performance-wise and unfriendly usability-wise, and can cause the browser to hang as you're experiencing.
Feb 6 '07 #4

P: 4
Is there any particular reason why you must send it synchronously? It is unreliable performance-wise and unfriendly usability-wise, and can cause the browser to hang as you're experiencing.
The reason for this is that I'm using this request to delete some records from a grid in the UI. So i can't show any status to the user (for the delete operation) till I get a response back. Do u have any suggestions on this.

Also is it true that HTTP1.1 supports unlimited character length in the URL's (and not limited to 255 characters)

Regards
Harmik
Feb 6 '07 #5

100+
P: 143
The reason for this is that I'm using this request to delete some records from a grid in the UI. So i can't show any status to the user (for the delete operation) till I get a response back. Do u have any suggestions on this.

Also is it true that HTTP1.1 supports unlimited character length in the URL's (and not limited to 255 characters)

Regards
Harmik
That's exactly what Asynchronous operations are for. Do the work in the background, then dynamically display the status / changes, once the operation has completed, without reloading the page. If you think it will take some time for the operation to complete, you can display a small "working" animation, like a loading bar, or a spinning loading animations, then once the operation is complete, remove the animation and make the changes on the page. This way, the user isn't waiting on that result, they can also do other things on the page, whilst they're waiting.
Feb 6 '07 #6

acoder
Expert Mod 15k+
P: 16,027
You can still do it asynchronously. Just use the onreadystatechange to check the status. When its complete, it will be set to 4. See here for more details.
Feb 6 '07 #7

acoder
Expert Mod 15k+
P: 16,027
That's exactly what Asynchronous operations are for. Do the work in the background, then dynamically display the status / changes, once the operation has completed, without reloading the page. If you think it will take some time for the operation to complete, you can display a small "working" animation, like a loading bar, or a spinning loading animations, then once the operation is complete, remove the animation and make the changes on the page. This way, the user isn't waiting on that result, they can also do other things on the page, whilst they're waiting.
Yes, Steven, good explanation.
Feb 6 '07 #8

P: 4
Yes, Steven, good explanation.
Thanks a lot guys ... for all the help and guidance ...

Cheers
Harmik
Feb 6 '07 #9

acoder
Expert Mod 15k+
P: 16,027
You're welcome.
Feb 6 '07 #10

100+
P: 296
That's exactly what Asynchronous operations are for. Do the work in the background, then dynamically display the status / changes, once the operation has completed, without reloading the page. If you think it will take some time for the operation to complete, you can display a small "working" animation, like a loading bar, or a spinning loading animations, then once the operation is complete, remove the animation and make the changes on the page. This way, the user isn't waiting on that result, they can also do other things on the page, whilst they're waiting.

Can anyone give me a sample code for loading animation and then unloading?
Dec 31 '07 #11

acoder
Expert Mod 15k+
P: 16,027
Can anyone give me a sample code for loading animation and then unloading?
One way is to have a hidden div (visibility:hidden) which already contains the image. When you make the Ajax request, set it to visible.
Dec 31 '07 #12

100+
P: 296
One way is to have a hidden div (visibility:hidden) which already contains the image. When you make the Ajax request, set it to visible.

How to load the animation for Synchronous Ajax request?
Jan 4 '08 #13

acoder
Expert Mod 15k+
P: 16,027
How to load the animation for Synchronous Ajax request?
The same, but the animation may not run properly because with a synchronous request, the browser waits for the response. Why use a synchronous request anyway? It's better to just refresh the page instead.
Jan 4 '08 #14

100+
P: 296
The same, but the animation may not run properly because with a synchronous request, the browser waits for the response. Why use a synchronous request anyway? It's better to just refresh the page instead.
Actually I want to freeze the background while the Ajax is going on and also showing a GIF image(progress) .

How to do that ?
Jan 4 '08 #15

acoder
Expert Mod 15k+
P: 16,027
Actually I want to freeze the background while the Ajax is going on and also showing a GIF image(progress) .

How to do that ?
With a synchronous request, the browser will freeze, so your animated image will show, but it may not be animated! Show the image before you make the request and possibly some text to explain what's happening. I think a non-Ajax solution makes more sense here, but that's just my opinion.
Jan 4 '08 #16

100+
P: 296
With a synchronous request, the browser will freeze, so your animated image will show, but it may not be animated! Show the image before you make the request and possibly some text to explain what's happening. I think a non-Ajax solution makes more sense here, but that's just my opinion.

I am saving the data present in cells of a spreadsheet so I think non Ajax is not good.
What do you think ?
Jan 5 '08 #17

acoder
Expert Mod 15k+
P: 16,027
I am saving the data present in cells of a spreadsheet so I think non Ajax is not good.
What do you think ?
The only reason why I think it's better not to use 'Ajax' here is that you're planning to use a synchronous request. This freezes the browser until a response is received which goes against the whole concept of Ajax. Why not use an asynchronous request? Does it take a long time for the server-side script to be processed?
Jan 5 '08 #18

Post your reply

Sign in to post your reply or Sign up for a free account.