私はajaxを使用してWebサービスを呼び出しています。しかし、firebugの出力を確認すると、400の不正な要求エラーが発生します。エラーが発生する理由を教えてください。なぜエラーが発生するのですか。次のコードに何か問題があります。次は私が書いたコードです:
<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で受け取る出力です。
リクエストヘッダー:オプション/Services/TransactionService.svc?wsdl HTTP / 1.1ホスト:development.virtualpiggy.com接続:keep-alive Access-Control-Request-メソッド:POSTオリジン:http ://test.com ユーザーエージェント:Mozilla /5.0(Windows NT 6.0)AppleWebKit / 537.11(KHTML、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 Set-Cookie:SessionId = ovpsrxt33jyoi3pzidvxkh0o; パス=/; 安全; HttpOnly X-AspNet-バージョン:4.0.30319X-Powered-By:ASP.NET