Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Responsetext returns entire html page

  • 19-03-2009 10:31PM
    #1
    Registered Users, Registered Users 2 Posts: 4,329 ✭✭✭


    You've probably come across this problem before. I have an Ajax site that has a response.write call in a c# page. This response is read on a javascript function as XMLHTTP.responseText.
    It is returning what I want but there is an entire page of html after it. I have other places on the site where XMLHTTP.responseText is returned and there is no problem.
    I think it is because previously on the button that calls the XMLHTTP.responseText there is another function that calls displays XMLHTTP.responseText.
    I actually had this problem before and it fixed itself but I can't remember how.
    I googled it and it said you can't get rid of it, you just have to parse out the part you want. Surely this can't be correct?
    I could parse it but it's not reliable.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 9,220 Mod ✭✭✭✭mewso


    The code that is writing the response should finish with response.end or else the complete html of the page will render.


  • Registered Users, Registered Users 2 Posts: 4,329 ✭✭✭lukin


    musician wrote: »
    The code that is writing the response should finish with response.end or else the complete html of the page will render.

    It does.:)


  • Moderators, Science, Health & Environment Moderators Posts: 9,220 Mod ✭✭✭✭mewso


    Is it running in the page load event? When I do this the ajax call to the page adds a querystring of callback=true for example. I check for this querystring in the page load and run a procedure determined by the querystring callbackid otherwise the page loads normally. I would also have response.flush before response.end. You probably have that anyway.


  • Registered Users, Registered Users 2 Posts: 4,329 ✭✭✭lukin


    It is running in the page load event actually. I don't have Response.flush (didn't know it existed). I have tried response.everything else!
    I'll give your suggestions a go, thanks.


  • Registered Users, Registered Users 2 Posts: 4,329 ✭✭✭lukin


    Still displaying a load of HTML, I've changed the C# code to this:
    Session.Clear();
                                Response.ClearContent();
                                Response.End();
                                string ren2 = ListOfIDs;
                                Response.ContentType = "text/plain";
                                Response.Write(ren2);
                                Response.Flush();
                                Response.End();
    

    When I put an alert in the client JavaScript code like so:

    alert(XMLHTTP.responseText);

    the alert box displays the list of ids at the top but a load of html straight after it.

    When I run it on my local pc it just returns what I want (the ListOfIDs) but on the live site it does the above.:confused:

    If I can't get it to just return the variable, then is there a way I can edit the responsetext in C# to make it delete the html?


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 9,220 Mod ✭✭✭✭mewso


    Whats the purpose of the response.end at the beginning? Maybe try removing it.


  • Registered Users, Registered Users 2 Posts: 4,329 ✭✭✭lukin


    Did that and it still returns HTML. I am sick of it at this stage now, I am just going to use a javascript function on the client code to strip everything after the first occurrence of "<" in the responsetext as no matter what I do server side it returns html every time.
    I cannot understand why something which works on localhost does not work the same on the live version.
    Thanks for the replies anyway.


Advertisement