leolee1993atlive
7/11/2019 - 9:15 AM

ajax通过soap访问WebService

function callAjaxWebservice() {
    var data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                "xmlns:ser=\"http://webService.clipathway.funso.com/\">" +
                    "<soapenv:Header/>" +
                        "<soapenv:Body>" +
                            "<ser:functionName>" +
                                "<paramName>wu</paramName>" +
                            "</ser:functionName>" +
                        "</soapenv:Body>" +
                    "</soapenv:Envelope>";

    console.log("call ajax");
    try {
        $.ajax({
            type: "POST", //访问WebService使用post方式请求
            contentType: "text/xml;utf-8", //使用的xml格式的
            url: "http://localhost:8080/xxxx/cxf/xxxx", //调用WebService的地址和方法名称组合
            data: data, //这里是要传递的参数
            dataType: "xml", //参数类型为xml
            success: function (result) {
                console.log("call succ:");
                console.log(result);
            },
            error: function (res, err) {
                console.log("call failed:" + res.responseText);
            }
        })
    } catch (ex) {
        console.log(ex);
    }
}