ChaoBaby94
ChaoBaby94
2016-02-27 02:40

ajax方式调用WebService

  • ajax
  • web service
    $.ajax({
        url:'http://127.0.0.1:6789/hello',type:'post',
        contentType:'text/xml;charset=utf-8',
        data:'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.demo2/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
            '<soapenv:Body><q0:sayHello><arg0>aaa</arg0></q0:sayHello></soapenv:Body></soapenv:Envelope>',
        dataType:'xml',
        success:function(msg){
            // ...
            alert("调用WebService成功!");
        },
        error:function(XMLHttpRequest,textStatus,errorThrown){
            alert("ajax调用错误!");
        }
    });

    然后HelloService的控制台输出:二月 27, 2016 10:35:03 上午 com.sun.xml.internal.ws.transport.http.server.WSHttpHandler handleExchange

警告: 无法处理 HTTP 方法: OPTIONS

网页的控制台:OPTIONS http://127.0.0.1:6789/hello net::ERR_EMPTY_RESPONSE

n.ajaxTransport.k.cors.a.crossDomain.send @ jquery.min.js:4
n.extend.ajax @ jquery.min.js:4
(anonymous function) @ ajax_ws.html:33
n.event.dispatch @ jquery.min.js:3
n.event.add.r.handle @ jquery.min.js:3

肿么解决!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答