XMLhttp request problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sudhaoncyberworld@gmail.com

    XMLhttp request problem

    Hi all

    i am using asp.net v2.0

    In one of my page i am calling another page using xml http , this is
    working fine but first time only ,

    I am sending the request on click of button , when i click the button
    second time, it's returning the previous response and it's not even
    calling that page again, where could be the problem.

    client side (aspx page 1- javascript)

    var http=new ActiveXObject(" Msxml2.XMLHTTP" );
    http.open("GET" ,"Gensparql.asp x",false);
    http.send();
    if(http.readySt ate == 4)
    {
    if(http.respons eText!=null && http.responseTe xt!='' )
    {
    //my process
    }
    }

    server side (aspx page 2)

    Response.Clear( );
    Response.Conten tType = "text/xml";
    Response.Write( retVal);
    Response.End();

    //second time returning same previous output and not calling the aspx
    page 2
    Hope u understand my problem,i am in urgent, Thanks in advance

  • knocte

    #2
    Re: XMLhttp request problem

    sudhaoncyberwor ld@gmail.com escribió:[color=blue]
    > Hi all
    >
    > i am using asp.net v2.0
    >
    > In one of my page i am calling another page using xml http , this is
    > working fine but first time only ,
    >
    > I am sending the request on click of button , when i click the button
    > second time, it's returning the previous response and it's not even
    > calling that page again, where could be the problem.
    >
    > client side (aspx page 1- javascript)
    >
    > var http=new ActiveXObject(" Msxml2.XMLHTTP" );
    > http.open("GET" ,"Gensparql.asp x",false);
    > http.send();
    > if(http.readySt ate == 4)
    > {
    > if(http.respons eText!=null && http.responseTe xt!='' )
    > {
    > //my process
    > }
    > }
    >
    > server side (aspx page 2)
    >
    > Response.Clear( );
    > Response.Conten tType = "text/xml";
    > Response.Write( retVal);
    > Response.End();
    >
    > //second time returning same previous output and not calling the aspx
    > page 2
    > Hope u understand my problem,i am in urgent, Thanks in advance
    >[/color]


    Perhaps you must send HTTP headers informing about how cacheable is the
    content. You could write it so as to expire immediately. BTW, don't use
    only ActiveX, or else other (standards compliant) browsers won't work
    with your page.

    Andrew [ knocte ]

    --

    Comment

    • Jambalaya

      #3
      Re: XMLhttp request problem

      Append a random number after the url that's being called. The browser
      will not use the cache. Just make sure to use a different random number
      for each call.

      http.open("GET" ,"Gensparql.asp x?nocache=46873 2156795431",fal se);

      Comment

      • Randy Webb

        #4
        Re: XMLhttp request problem

        Jambalaya said the following on 10/12/2005 10:25 AM:[color=blue]
        > Append a random number after the url that's being called.[/color]

        And what is that for?
        [color=blue]
        > The browser will not use the cache.[/color]

        It will if I tell it to.
        [color=blue]
        > Just make sure to use a different random number for each call.[/color]

        Each call of what?
        [color=blue]
        >
        > http.open("GET" ,"Gensparql.asp x?nocache=46873 2156795431",fal se);
        >[/color]

        Oh wait, I see now. If you had bothered to quote what you were replying
        to it would be easier to see that your approach has a simple flaw in it.
        Instead of just trying to guess at a random number, you append the
        current time in milliseconds.

        --
        Randy
        comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
        Answer:It destroys the order of the conversation
        Question: Why?
        Answer: Top-Posting.
        Question: Whats the most annoying thing on Usenet?

        Comment

        • Jambalaya

          #5
          Re: XMLhttp request problem

          >Oh wait, I see now. If you had bothered to quote what you were replying[color=blue]
          >to it would be easier to see that your approach has a simple flaw in it.
          >Instead of just trying to guess at a random number, you append the
          >current time in milliseconds.[/color]

          There was no flaw. Just a different method to accomplish the goal.

          --
          Jambalaya
          Question: What's the #2 most annoying thing on Usenet?
          Answer: Netiquette Nazis.

          Comment

          • Randy Webb

            #6
            Re: XMLhttp request problem

            Jambalaya said the following on 10/13/2005 12:22 AM:
            [color=blue][color=green]
            >>Oh wait, I see now. If you had bothered to quote what you were replying
            >>to it would be easier to see that your approach has a simple flaw in it.
            >>Instead of just trying to guess at a random number, you append the
            >>current time in milliseconds.[/color]
            >
            >
            > There was no flaw. Just a different method to accomplish the goal.[/color]

            And what method is that? Since you did not elaborate and your code was
            hard-coded and showed no signs of being generated, it indicated that one
            should hard-code that random number. That is a flaw in the approach -
            not a different method to accomplish the same goal.

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
            Answer:It destroys the order of the conversation
            Question: Why?
            Answer: Top-Posting.
            Question: Whats the most annoying thing on Usenet?

            Comment

            • Jambalaya

              #7
              Re: XMLhttp request problem

              >>>Oh wait, I see now. If you had bothered to quote what you were replying[color=blue][color=green][color=darkred]
              >>>to it would be easier to see that your approach has a simple flaw in it.
              >>>Instead of just trying to guess at a random number, you append the
              >>>current time in milliseconds.[/color][/color][/color]
              [color=blue][color=green]
              >> There was no flaw. Just a different method to accomplish the goal.[/color][/color]
              [color=blue]
              >And what method is that?[/color]

              You really do seem smarter than this, Randy. I was showing the end
              result of the concatenation so that the original poster would
              understand the concept. I wasn't writing the code for him. I assume
              since he is using xmlhttp that he has sufficient javascript knowledge
              to be able to generate a random number and append it to a string.
              [color=blue]
              >Since you did not elaborate and your code was
              >hard-coded and showed no signs of being generated, it indicated that one
              >should hard-code that random number.[/color]

              No, if you will reread my first post, it indicates the opposite. I
              quote myself, "Just make sure to use a different random number for each
              call."
              [color=blue]
              >That is a flaw in the approach -
              >not a different method to accomplish the same goal.[/color]

              I guess I'll admit there was a flaw. And that is that I didn't write
              all the javascript for the original poster. I guess I'm more of a
              teach-a-man-to-fish sort of guy versus a give-a-man-a-fish guy.

              J

              Comment

              • Andrew Stephanoff

                #8
                Re: XMLhttp request problem

                1.You must generate XML-content on php or ASP and set th header with
                following info: "Content-type: application/xml; Cache-control:
                no-cache;". If you use "clear" XML, the content will be cached.
                2. Code in javascript will be follow:

                var http;
                if (window.XMLHttp Request) {
                try {http = new XMLHttpRequest( );}
                catch(e){http = false;}
                } else if (window.ActiveX Object("Microso ft.XMLHTTP")) {
                try {http = new window.ActiveXO bject("Microsof t.XMLHTTP");}
                catch(e) {
                try {http = new window.ActiveXO bject("Msxml2.X MLHTTP");}
                catch(e){http = false;}
                } else {
                http = false;
                }
                http.open("GET" ,"Gensparql.asp x",true);
                http.onreadysta techange = function() {
                if (http.readyStat e == 4)
                if (http.status == 200) {
                //my process
                }
                }
                http.send(null) ;

                Comment

                • Randy Webb

                  #9
                  Re: XMLhttp request problem

                  Jambalaya said the following on 10/13/2005 4:30 AM:
                  [color=blue][color=green][color=darkred]
                  >>>>Oh wait, I see now. If you had bothered to quote what you were replying
                  >>>>to it would be easier to see that your approach has a simple flaw in it.
                  >>>>Instead of just trying to guess at a random number, you append the
                  >>>>current time in milliseconds.[/color][/color]
                  >
                  >[color=green][color=darkred]
                  >>>There was no flaw. Just a different method to accomplish the goal.[/color][/color]
                  >
                  >[color=green]
                  >>And what method is that?[/color]
                  >
                  >
                  > You really do seem smarter than this, Randy. I was showing the end
                  > result of the concatenation so that the original poster would
                  > understand the concept. I wasn't writing the code for him. I assume
                  > since he is using xmlhttp that he has sufficient javascript knowledge
                  > to be able to generate a random number and append it to a string.[/color]

                  Now it makes sense :)
                  [color=blue]
                  >[color=green]
                  >>Since you did not elaborate and your code was
                  >>hard-coded and showed no signs of being generated, it indicated that one
                  >>should hard-code that random number.[/color]
                  >
                  >
                  > No, if you will reread my first post, it indicates the opposite. I
                  > quote myself, "Just make sure to use a different random number for each
                  > call."[/color]

                  Fair enough.
                  [color=blue]
                  >[color=green]
                  >>That is a flaw in the approach -
                  >>not a different method to accomplish the same goal.[/color]
                  >
                  >
                  > I guess I'll admit there was a flaw. And that is that I didn't write
                  > all the javascript for the original poster. I guess I'm more of a
                  > teach-a-man-to-fish sort of guy versus a give-a-man-a-fish guy.[/color]

                  That's probably why I didn't write the script either, huh? <g>

                  --
                  Randy
                  comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                  Comment

                  • Richard Cornford

                    #10
                    Re: XMLhttp request problem

                    Jambalaya wrote:
                    <snip>[color=blue][color=green]
                    >>... , it indicated that
                    >>one should hard-code that random number.[/color]
                    >
                    > No, if you will reread my first post, it indicates the
                    > opposite. I quote myself, "Just make sure to use a
                    > different random number for each call."[/color]

                    It is considerably easier to say "just make sure to use a different
                    random number for each call" (assuming "call" is acceptable terminology
                    here (which it probably isn't)) than to actually do it. Remember that
                    you would have to be keeping track of which random numbers had been
                    used, even between sessions, as it would not be too good if the browser
                    decided to deliver content that it had downloaded in a previous session
                    from its cache in response to a request in a later one.

                    That is why using the millisecond time in this context has been
                    proposed, as each time will be unique (at least so long as no two times
                    are requested within about 60 milliseconds, at most) and it is in the
                    nature of time that is does not repeat itself. That is; what is wanted
                    is a unique number rather than a random one, and each item in a sequence
                    of increasing integer values is unique within that sequnce.
                    [color=blue][color=green]
                    >>That is a flaw in the approach -
                    >>not a different method to accomplish the same goal.[/color]
                    >
                    > I guess I'll admit there was a flaw.[/color]

                    Yes it is. At lest in part because the proposal that the OP should "make
                    sure" that no two random numbers be the same is considerably more
                    troublesome than an available alternative.
                    [color=blue]
                    > And that is that I didn't write
                    > all the javascript for the original poster.
                    > I guess I'm more of a teach-a-man-to-fish sort
                    > of guy versus a give-a-man-a-fish guy.[/color]

                    "Fishing" in an HTTP context would be better mastered with an
                    understanding of HTTP, and specifically the way in which various HTTP
                    headers can be configured to discourage client-side caching of various
                    resources (and possibly the different ways in which POST and GET
                    requests are handled with regard to caching). With the correct header
                    configuration it is possible that the URL hack would be unnecessary,
                    else you would see such "random numbers" on the end of every URL on
                    every dynamic site.

                    Richard.


                    Comment

                    • Jambalaya

                      #11
                      Re: XMLhttp request problem


                      Richard Cornford wrote:
                      <snip>[color=blue]
                      > It is considerably easier to say "just make sure to use a different
                      > random number for each call" (assuming "call" is acceptable terminology
                      > here (which it probably isn't)) than to actually do it. Remember that
                      > you would have to be keeping track of which random numbers had been
                      > used, even between sessions, as it would not be too good if the browser
                      > decided to deliver content that it had downloaded in a previous session
                      > from its cache in response to a request in a later one.[/color]

                      Agreed. However, the odds that the same random number would be
                      generated within the lifespan of the cache is sufficiently miniscule to
                      preclude the need to keep track of the used numbers. (Especially
                      considering the example I used provided for up to 1 quadrillion
                      numbers.)
                      [color=blue]
                      > That is why using the millisecond time in this context has been
                      > proposed, as each time will be unique (at least so long as no two times
                      > are requested within about 60 milliseconds, at most) and it is in the
                      > nature of time that is does not repeat itself. That is; what is wanted
                      > is a unique number rather than a random one, and each item in a sequence
                      > of increasing integer values is unique within that sequnce.[/color]

                      It cannot be guaranteed that each time will be unique. JavaScript uses
                      the system clock. Granted, the odds that a user will change the time
                      and a second request goes out with the same millisecond timestamp is
                      very small. Perhaps 1 in a trillion? ;)
                      [color=blue][color=green][color=darkred]
                      > >>That is a flaw in the approach -
                      > >>not a different method to accomplish the same goal.[/color]
                      > >
                      > > I guess I'll admit there was a flaw.[/color]
                      >
                      > Yes it is. At lest in part because the proposal that the OP should "make
                      > sure" that no two random numbers be the same is considerably more
                      > troublesome than an available alternative.[/color]

                      I agree that it would be. But, again, the odds are remote enough to
                      preclude the need to do so.
                      [color=blue]
                      >[color=green]
                      > > And that is that I didn't write
                      > > all the javascript for the original poster.
                      > > I guess I'm more of a teach-a-man-to-fish sort
                      > > of guy versus a give-a-man-a-fish guy.[/color]
                      >
                      > "Fishing" in an HTTP context would be better mastered with an
                      > understanding of HTTP, and specifically the way in which various HTTP
                      > headers can be configured to discourage client-side caching of various
                      > resources (and possibly the different ways in which POST and GET
                      > requests are handled with regard to caching). With the correct header
                      > configuration it is possible that the URL hack would be unnecessary,
                      > else you would see such "random numbers" on the end of every URL on
                      > every dynamic site.[/color]

                      We agree again! But as this is a JavaScript Usenet group, the
                      workaround(hack ) suggested involved JavaScript. But just so you know
                      that I'm not being stubbornly argumentative, I'll agree that the
                      millisecond method is superior assuming no user clock adjustments. The
                      random number method would be superior for requests made within 50
                      milliseconds of each other.

                      Now that I think about it, both methods should be used simultaneously.
                      Append the random number after the millisecond timestamp and then you
                      have a workaround that avoids the simultaneous request problem and the
                      user clock adjustment problem. Genious!

                      Comment

                      • Dr John Stockton

                        #12
                        Re: XMLhttp request problem

                        JRS: In article <dim3m7$a4p$1$8 300dec7@news.de mon.co.uk>, dated
                        Thu, 13 Oct 2005 17:57:42, seen in news:comp.lang. javascript,
                        Richard Cornford <Richard@litote s.demon.co.uk> posted :[color=blue]
                        >
                        >That is why using the millisecond time in this context has been
                        >proposed, as each time will be unique (at least so long as no two times
                        >are requested within about 60 milliseconds, at most) and it is in the
                        >nature of time that is does not repeat itself.[/color]

                        For the present purpose, that, if correctly interpreted, will
                        do.

                        However, the current time has to be in a form not affected by
                        Summer Time (a civil hour in Autumn is repeated, in many
                        places); and, for travellers, by change in location : so UTC
                        should be used, and +new Date() will give that.

                        Also, any system in which a drifty clock is corrected by
                        reference to a time source is liable to have repeated times.

                        Real Greenwich Mean Time and Real UTC are monotonic, increasing
                        by close to / exactly one second per second; buy, when it really
                        matters, one should allow for a computer's estimate of time to
                        be non-monotonic.

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                        Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                        Comment

                        Working...