0

这是我的客户端代码。调用此函数时,我收到 400 错误请求错误。谁能帮助我。

var req_params="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
              req_params = req_params + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
              req_params = req_params + "<soap:Header>";
             req_params = req_params + "<UserDetails>";
             req_params = req_params + "<Lastname>Abubakar</Lastname>";
             req_params = req_params + "<Othernames>Uju, Ayo</Othernames>";
             req_params = req_params + "<Email>me@me.com</Email>";
              req_params = req_params + "<Phone>08032458829</Phone>";
             req_params = req_params + "</UserDetails>";
             req_params = req_params + "</soap:Body>";
             req_params = req_params + "</soap:Envelope>";
             console.log(req_params);
    $.ajax({
    type: "POST",
    url: "http://testservices.interswitchng.com/quicktellerservice/quickteller.svc/CreateUser",
    data: req_params, 
    processData:false,
    contentType: "text/xml; charset=\"utf-8\"",
    dataType: "xml",
    success: function (data) {
        console.log(data);
    },        
    error: function (xhr, status, error) {
        alert(error);
    } 
});
4

1 回答 1

0

这样做的原因是您不能在不修改您正在使用的 Web 服务的情况下进行跨域调用。如果你用谷歌搜索“jquery cross domain ajax”,你可以找到更多关于这个的信息。

在这里您可以阅读更多相关信息:http ://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/

在这里你会找到一个跨域 XML 调用的例子:http ://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-xml-response-for-iefirefoxchrome-safari-jquery/

于 2012-12-24T10:41:29.730 回答