【发布时间】:2016-03-12 15:24:03
【问题描述】:
我目前正在尝试向 Authorize.net AIM api 发出请求。我已经在 Post Man 中成功发送了帖子。我遇到的问题与发布的数据必须在 xml 中有关。当我尝试如下例所示将数据设置为 xml 时,我收到 Unexpected token ILLEGAL 错误。对这个错误的任何帮助都会很棒。此外,如果有更好的方法来格式化帖子的 xml,请告诉我我已经环顾四周,但没有成功。
$.ajax({
type : "POST",
url : "https://apitest.authorize.net/xml/v1/request.api",
data : "<createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>xxxxxxxxxxx</name>
<transactionKey>xxxxxxxxxxx</transactionKey>
</merchantAuthentication>
<refId>123456</refId>
<transactionRequest>
<transactionType>authCaptureTransaction</transactionType>
<amount>5</amount>
<payment>
<creditCard>
<cardNumber>5424000000000015</cardNumber>
<expirationDate>1220</expirationDate>
<cardCode>999</cardCode>
</creditCard>
</payment>
<order>
<invoiceNumber>INV-12345</invoiceNumber>
<description>Product Description</description>
</order>
<lineItems>
<lineItem>
<itemId>1</itemId>
<name>vase</name>
<description>Cannes logo </description>
<quantity>18</quantity>
<unitPrice>45.00</unitPrice>
</lineItem>
</lineItems>
<tax>
<amount>4.26</amount>
<name>level2 tax name</name>
<description>level2 tax</description>
</tax>
<duty>
<amount>8.55</amount>
<name>duty name</name>
<description>duty description</description>
</duty>
<shipping>
<amount>4.26</amount>
<name>level2 tax name</name>
<description>level2 tax</description>
</shipping>
<poNumber>456654</poNumber>
<customer>
<id>99999456654</id>
</customer>
<billTo>
<firstName>Ellen</firstName>
<lastName>Johnson</lastName>
<company>Souveniropolis</company>
<address>14 Main Street</address>
<city>Pecan Springs</city>
<state>TX</state>
<zip>44628</zip>
<country>USA</country>
</billTo>
<shipTo>
<firstName>China</firstName>
<lastName>Bayles</lastName>
<company>Thyme for Tea</company>
<address>12 Main Street</address>
<city>Pecan Springs</city>
<state>TX</state>
<zip>44628</zip>
<country>USA</country>
</shipTo>
<customerIP>192.168.1.1</customerIP>
<transactionSettings>
<setting>
<settingName>testRequest</settingName>
<settingValue>false</settingValue>
</setting>
</transactionSettings>
<userFields>
<userField>
<name>MerchantDefinedFieldName1</name>
<value>MerchantDefinedFieldValue1</value>
</userField>
<userField>
<name>favorite_color</name>
<value>blue</value>
</userField>
</userFields>
</transactionRequest>
</createTransactionRequest>",
dataType : "xml",
success : function(msg){
console.log("success");
}
error : function(msg) {
console.log("fail");
}
});
【问题讨论】:
-
查看双引号字符串中出现的 XML 中的双引号。这行不通。
标签: javascript ajax xml api authorize.net