webservice jsonp格式调用

时间:2023-12-28 20:27:14

前端

 $.ajax({
            type: "get",
            url: "webservice jsonp格式调用http://baiduzd.yihu.com.cn/APIService.asmx/GetHospitalStatus",
            dataType: "jsonp",
            jsonp: 'callback',  
            data: { "HospitalID": 1111 },
            success: function(result) {
                //返回结果
                alert(result.status);
            },
            error: function() {
                //返回结果
                alert("1111");
            }
        });
后端

[WebMethod]
[ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)]
public void GetHospitalStatus(string HospitalID)
{
string strStatus = GetHospitalInfo.GetHospitalStatus(HospitalID);
HttpContext.Current.Response.Write(HttpContext.Current.Request["callback"] + "({'status':" + strStatus + "})");
}