2012-04-02 30 views
0

我有follwing方法Scriptmethod responseformat设置为JSON返回XML

[WebMethod] 
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)] 
public List<MyObject> GetMyObjects() 
    { 
     return Business.GetMyObjects(); 
    } 

,你可以看到Web方法设置为JSON,但该方法返回XML

我使用以下JavaScript访问此Web方法。

function getMyObjects() { 
$.ajax({ 
    type: "POST", 
    url: "/treenode/myobjects.asmx/GetMyObjects", 
    dataType: "JSON" 
}).success(function(data) { 
    var response = data.d; 
    alert(d.param); 
}); 
} 

这可能是一个快速修复,但我错过了一些东西,不能看到它是什么。

回答

1

通过添加

contentType: 'application/json; charset=utf-8' 

一个Ajax选项我克服了错误