I am getting a javascript error on firefox 3.5, when trying to call an ajax method.
Please find the error below:
XML Parsing Error: no element found
I've come across an alternative cause of this - might help someone.
If you make a $.ajax
request (in my case a PUT
request) that returns a 200 header but no body content I've seen this same XML Parsing error message occur - even when the dataType
is set to json
.
(At least) two solutions work:
PUT
requests return some content, orasync
is also part of options. Also specify the dataType
as xml
function Update(Id) {
$.ajax({
type: "GET",
async: false,
dataType: "XML",
url: ROOT_URL + "/sevice/udates.svc/Update?Id=" + Id,
success: function(response) {
}
});
}
You need to send html document to the output (the output udates.svc in your case) . If you use ASP.NET, you could do the following:
Response.Clear();
Response.Write("<html xmlns=”http://www.w3.org/1999/xhtml”>");
Response.Write("<head><title></title></head>");
Response.Write("<body>");
Response.Write("your output");
Response.Write("</body>");
Response.Write("</html>");
Response.ContentType = "text/HTML";
Response.End();
It's a known FireFox bug. https://bugzilla.mozilla.org/show_bug.cgi?id=547718 to quick fix this , you maybe can return an response with html structure(but no content).
The ajax call expects XML back (perhaps due to bad guessing) and tries to parse it and fails if nothing is returned or it is not valid XML..
Use the dataType
option to specify the format of the response.
From the comments it looks like some browsers cannot handle an no-content response. So, a workaround for such cases might be to return something from your service (even a single space).
I fixed the problem by setting mimeType to "text/html"