Skip to main content
 首页 » 编程设计

c#之如何从 webservice 返回 xml 数据到 jquery ajax 调用

2024年02月03日31xing901022

这是我对 webservice -JsonWebService.asmx 文件的 ajax 调用

 $.ajax({ 
                    type: "POST", 
                    async: false,  
                    url: "/blkseek2/JsonWebService.asmx/GetList", 
                    data: keyword2, 
                    contentType: "application/xml; charset=utf-8", 
                    success: ajaxCallSucceed, 
                    dataType: "xml", 
                    failure: ajaxCallFailed 
                }); 

这是我的成功方法,我将如何在成功方法中捕获 xml 响应

function ajaxCallSucceed(response) { 
    alert(response.d); 
    /// here i need to write code to capture response xml doc file 
} 

这是我在 webservice jsonwebservice.asmx.cs 文件中编写的代码,我能够完全成功地创建 xml,但我发现很难将 xml 返回给 ajax 调用

[WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public XmlDocument GetList(string keyword1, string streetname, string lat, string lng, string radius) 
    { 
        XmlDocument xmldoc= CreateXML( keyword1,streetname,lat,lng,radius); 
 
 
 
        return xmldoc; 
 
    } 

请您参考如下方法:

如下更改您的网络方法并重试:

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)] 
public XmlDocument GetList(string keyword1, string streetname, string lat, string lng, string radius) { 
    XmlDocument xmldoc = CreateXML(keyword1, streetname, lat, lng, radius); 
    return xmldoc; 
}