Wednesday, February 17, 2010

XML Parsing Error: no element found

        Today while working with JQuery-Ajax, I found an interesting error. I have used $.ajax() function to retrieve data from remote page. While testing I found that the page always show error : XML Parsing Error: no element found. Error does not contain specific information about the source of error. The common reason for XML Parsing Error: no element found is missing closing tag for one or two html element, so I double checked everything to make sure not miss any closing(</td> </tr>) tags.

        After searching for while I found that somehow ASP.NET treat the response of page as XML document and that’s why we receive XML Parsing Error: no element found error.

        To solve this error I added a line Response.ContentType = "text/HTML" to .cs page. This line tells ASP.NET runtime that response is HTML text and not XML.

Happy Programming!!!

1 comment:

Pooja said...

Is it possible for you tell where did you inserted the Response.ContentType=text/HTML statement to?
I am a new asp c#.net programmer and trying to fix the same problem on my application. I am doing a POST from my Javascript to be caught in webservice on server side . And not returning any value what so ever for this Webmethod. But i get the same error on FireBug in Mozilla...

Please Help.. many thanks in anticipation :)