0

我的网络服务有问题。当我以 POST 和 JSON 格式传递参数时,它返回一个 JSON 对象。我想将 POST 转换为 GET,但问题是,Web 服务仅以 XML 格式返回。

<script>   
$.ajax({
        type: "GET",
        url: "/web_services/webservice.asmx/getReturnJson",
        data: "params1=1",
        contentType: "application/*; charset=utf-8",
        dataType: "json")
</script>

网络服务:

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat=ResponseFormat.Json)]
    public List<tempStruct> getReturnJson(String params1)
    { 
     return temp;
    }
4

2 回答 2

0

如果您遇到 GET 参数无法正确解析的问题,请在 URL 中设置它们。

$.ajax({
    type: "GET",
    url: "/web_services/webservice.asmx/getReturnJson?params=1",
    contentType: "application/json; charset=utf-8")

还要确保你有所有合适的配置。

<httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory"     validate="false"/>
</httpHandlers>
于 2012-06-13T05:12:39.120 回答
0

发现出于安全原因它不接受 POST 请求

于 2012-12-14T06:26:36.003 回答