我想通过 jQuery 和 AJAX 与 UPS API 进行通信。XML 似乎格式正确,因为它在类似的 ASP 脚本中运行良好。但我想我会跳过 ASP 脚本并通过 jQuery 直接与 UPS 通信。但是,当我发送请求时,响应显示为:
方法:选项
状态:已取消加载
我假设我错过了 ajax 请求中的某种选项,告诉它将 xml 发送到 UPS 服务器。
$(document).ready(function() {
$.ajax({ type: "POST",
url: "https://wwwcie.ups.com/ups.app/xml/XAV",
data: "<?xml version=1.0?>" +
" <AccessRequest xml:lang='en-US'>" +
" <AccessLicenseNumber>LICENSENUMBER</AccessLicenseNumber>" +
" <UserId>USER</UserId>" +
" <Password>PASS</Password>" +
" </AccessRequest>" +
" <?xml version=1.0?>" +
" <AddressValidationRequest xml:lang='en-US'>" +
" <Request>" +
" <TransactionReference>" +
" <CustomerContext>AddressValidationRequest</CustomerContext>" +
" <XpciVersion>1.0</XpciVersion>" +
" </TransactionReference>" +
" <RequestAction>XAV</RequestAction>" +
" <RequestOption>3</RequestOption>" +
" </Request>" +
" <AddressKeyFormat>" +
" <AddressLine>1234 N. Main Street</AddressLine>" +
" <PoliticalDivision2>Los Angeles</PoliticalDivision2>" +
" <PoliticalDivision1>CA</PoliticalDivision1>" +
" <PostcodePrimaryLow>90210</PostcodePrimaryLow>" +
" <CountryCode>US</CountryCode>" +
" </AddressKeyFormat>" +
" </AddressValidationRequest>",
contentType: "text/xml",
dataType: "xml",
cache: false,
error: function() { alert("No data found."); },
success: function(xml) {
alert("it works");
alert($(xml).find("project")[0].attr("id"));
}
});
});