views:

166

answers:

3

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
    });
}
+1  A: 

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.

Gaby
so u mean to say that i need to some thing like what Teja told?
Nimesh
@Nimesh, yep .. but it depends on what you expect to receive back from the service.. is it XML ? or is it JSON ? HTML ? Text ?
Gaby
JSON is the format. I am using an attribute decorated on the WCF service method as WebMessageFormat.Json
Nimesh
@Nimesh, your should add `dataType: 'json'` then in your options to the ajax call.. You should also use firebug to check the response from the server and see if it returns what you expect it ..
Gaby
Gaby, Actually my method return's null from the webservice, it is a void method. So if i give datatype : json, will I able to solve the issue?
Nimesh
@Nimesh, if you do not expect to get something back from the server. perhaps you should use the `dataType:'text'`. It should not try to do something with a text response...
Gaby
still i am gettign the same error
Nimesh
A: 

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) {

        }
    });
}
Teja Kantamneni
A: 

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”&gt;");
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();
Stamen