Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Responsetext returns entire html page

  • 19-03-2009 9:31pm
    #1
    Registered Users, Registered Users 2 Posts: 4,114 ✭✭✭


    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,035 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,114 ✭✭✭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,035 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,114 ✭✭✭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,114 ✭✭✭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,035 Mod ✭✭✭✭mewso


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


  • Registered Users, Registered Users 2 Posts: 4,114 ✭✭✭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