Reputation: 5507
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 Location: moz-nullprincipal:{1a2c8133-f48f-4707-90f3-1a2b2f2d62e2} Line Number 1, Column 1:
^
this is my javascript function:
function Update(Id) {
$.ajax({
type: "GET",
url: ROOT_URL + "/sevice/udates.svc/Update?Id=" + Id,
success: function(response) {
},
async: false
});
}
Upvotes: 22
Views: 29122
Reputation: 196217
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).
Upvotes: 19
Reputation: 4350
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, orUpvotes: 10
Reputation: 151
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).
Upvotes: 5
Reputation: 613
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();
Upvotes: 0
Reputation: 17482
async
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) {
}
});
}
Upvotes: 0