JQuery AJAX, Error Status code: 200, Status Text: parserorro | OK

Here is a funny situation that I'm in. I'm developing an ASP.Net web site using VS 2008 and .Net Framework 3.5, and I want to use jquery ajax in a test page, the code looks like this:

C# Method
[WebMethod]
public static string test()
{
    return "Server Response" ;
}

$(document).ready(function() {
    $("#myDiv").click(function() {
        $.ajax({
            type: "POST",
            url: "AjaxTest.aspx/test",
            data: "",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
                        success: function(msg) {
                            // Replace the div's content with the page 
                            // method's return.
                            alert(msg.d);
                        },
                        error: function(result){ 
                            alert("error occured. Status:" + result.status  
                            + ' --Status Text:' + result.statusText 
                            + " --Error Result:" + result); 
                        }
           });
    });
});

So When I use Jquery 1.4.4 like this :

I get : Status 200; Status Text: OK

When I use Jquery 1.5 I get: Status 200; Status Text: Parsererror

So I created a new WebSite in Visual Studio, copy and pased the code there, and it works fine !!!! I can't figure out what causes the problem. Also I have used methods with parameter, and setting data:"{}", and removing data completely, but nothing seems to work.

I don't know if has to do anything with the DevExpress components that I'm using or not.

I also found a good answer which was working with complete method like this :

  complete: function(xhr, status) {
            if (status === 'error' || !xhr.responseText) {
                alert("Error");
            }
            else {
                var data = xhr.responseText;
                alert(data);
                //...
            }
        }

But I don't know if it will work fine or there might be some other problem with this method too. I also don't know how to access response data from here. But my main concern is finding out what is causing the problem in my website.

UPDATE: Well today in Google Chrome console I noticed some syntax problems with JQuery 1.5 they are as below:

Uncaught SyntaxError: Unexpected token < jQuery.jQuery.extend.globalEvaljquery.js:593 jQuery.ajaxSetup.converters.text scriptjquery.js:7175 ajaxConvertjquery.js:7074 donejquery.js:6622 jQuery.ajaxTransport.send.callbackjquery.js:7441

5
задан Ali 8 April 2011 в 22:53
поделиться