HTTP Request from JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harmiksingh
    New Member
    • Feb 2007
    • 4

    #1

    HTTP Request from JavaScript

    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to The Scripts

    Instead of using the synchronous method, use asynchronous (the A in AJAX). See this page for more info.

    Comment

    • harmiksingh
      New Member
      • Feb 2007
      • 4

      #3
      Originally posted by acoder
      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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #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.

        Comment

        • harmiksingh
          New Member
          • Feb 2007
          • 4

          #5
          Originally posted by acoder
          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

          Comment

          • steven
            New Member
            • Sep 2006
            • 143

            #6
            Originally posted by harmiksingh
            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.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You can still do it asynchronously. Just use the onreadystatecha nge to check the status. When its complete, it will be set to 4. See here for more details.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by steven
                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.

                Comment

                • harmiksingh
                  New Member
                  • Feb 2007
                  • 4

                  #9
                  Originally posted by acoder
                  Yes, Steven, good explanation.
                  Thanks a lot guys ... for all the help and guidance ...

                  Cheers
                  Harmik

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    You're welcome.

                    Comment

                    • pankajit09
                      Contributor
                      • Dec 2006
                      • 296

                      #11
                      Originally posted by steven
                      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?

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by pankajit09
                        Can anyone give me a sample code for loading animation and then unloading?
                        One way is to have a hidden div (visibility:hid den) which already contains the image. When you make the Ajax request, set it to visible.

                        Comment

                        • pankajit09
                          Contributor
                          • Dec 2006
                          • 296

                          #13
                          Originally posted by acoder
                          One way is to have a hidden div (visibility:hid den) which already contains the image. When you make the Ajax request, set it to visible.

                          How to load the animation for Synchronous Ajax request?

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Originally posted by pankajit09
                            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.

                            Comment

                            • pankajit09
                              Contributor
                              • Dec 2006
                              • 296

                              #15
                              Originally posted by acoder
                              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 ?

                              Comment

                              Working...