简体   繁体   中英

How to return xml data to jquery ajax call from webservice

This is my ajax call to webservice -JsonWebService.asmx file

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

This is my method for success ,how will i capture xml response in success method

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

This is my code written in webservice jsonwebservice.asmx.cs file,I am able create xml sucess fully but i am finding difficulty in returning xml back to ajax call

[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;

    }

Change your web method as below and try again:

[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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM