0

我正在使用 ajax 来调用 web 服务。但是当我检查萤火虫中的输出时,我得到 400 bad request 错误。你能告诉我为什么我会得到这个错误。为什么我会收到错误消息。以下代码有什么问题吗?以下是我编写的代码:

<script>

    function HelloWorld() {

        var sDate = '<cart currency="USD" total="5.38"><cart-shipment total="5.38" shipment-reference="33261668"><shipment-tax total="0.39" /><shipment-cost total="0" /><shipment-address><address>33 W 59TH STREET APT 203 </address><zip>60559</zip><city>WESTMONT</city><state>IL</state><country>US</country><phone></phone><name>John Baker</name><attention-of>KID</attention-of></shipment-address><items><item total="4.99"><item-name>Hello Kitty - cupcake</item-name><item-description>Hello Kitty - cupcake</item-description><item-price>4.99</item-price><item-quantity>1</item-quantity></item></items></cart-shipment></cart>';


        var webMethod = "https://abc.com/Services/TransactionService.svc";

        var sr = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:ns2="vp">' +
               '<soapenv:Header/>' +
                    '<soapenv:Body>' +
                        '<tem:ProcessTransaction>' +
                            '<tem:checkOutData>' + sDate + '</tem:checkOutData>' +
                            '<tem:token>5OMc0y1miZN5EFqiZ8IiLn+mzdboyTuTob43Kp4+VcVtrYGQvl7QWJB5OeoPWQpBUej6LSejwE8f16tDhg1EUqDtGGAdn/MM3Gk8MOr0FvFko84ogfhIs9HCUjum2MUN1a/sALjhen+DareUP5wWbIpnu8Eaqg2Tv0RjEsq1bqYblHcXfKIq7anTDzYoHN8Y7LAXgdEhSrVcEIB3+sCCDQ==</tem:token>' +
                            '<tem:transactionDescription>Volusion Order Description</tem:transactionDescription>' +
                        '</tem:ProcessTransaction>' +
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';


        $.ajax({
            type: "POST",
            url: webMethod,
            data: sr,
            contentType: "text/xml",
            dataType: "xml",
            cache: false,
            success: OnSuccess,
            error: OnError
        });
        return false;

    }
    function OnSuccess(data, status) {

        alert(data);

    }

    function OnError(request, status, error) {

        alert(error);
    }


    </script>
    <div>
            <input type="button" value="Soap" onclick="HelloWorld();" />
        </div>

以下是我在 firebug 中收到的输出:

请求标头:OPTIONS /Services/TransactionService.svc?wsdl HTTP/1.1 主机:development.virtualpiggy.com 连接:keep-alive 访问控制请求方法:POST 来源:http ://test.com 用户代理:Mozilla /5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11 Access-Control-Request-Headers: origin, content-type, accept Accept: / Referer: http://test. com/Desktop/test_webservice.htm Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q =0.3

响应头:Access-Control-Allow-Origin:http://yann-asus:81 http://www.kkdmarketing.com Cache-Control:private Content-Length:0 Date:Tue, 04 Dec 2012 06:42: 23 GMT 服务器:Microsoft-IIS/7.0 设置-Cookie:SessionId=ovpsrxt33jyoi3pzidvxkh0o;路径=/; 安全的; HttpOnly X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET

4

1 回答 1

0

我会尝试在 contentType 中设置一个 utf-8 字符集

$.ajax({
        type: "POST",
        url: webMethod,
        data: sr,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        cache: false,
        success: OnSuccess,
        error: OnError
});
于 2012-12-04T06:50:19.017 回答