我能够使用ARC成功发布到createCustomerProfile端点,但是不能在javascript中使用简单的AJAX发布。我正在使用以下AJAX请求:
$.ajax({
type: "POST",
crossDomain: true,
url: 'https://apitest.authorize.net/xml/v1/request.api',
dataType: "json",
data: createCustomerProfileRequest,
success: function (response) {
if (response.dataValue == "Error") {
alert(response.dataDescriptor);
} else {
alert('Successfully sumitted payment!');
}
$("#ccButton").attr("disabled", false);
},
error: function (error) {
alert('Could NOT submit payment!');
$("#ccButton").attr("disabled", false);
}
});
我的数据已验证为以下数据:
"createCustomerProfileRequest": {
"merchantAuthentication": {
"name": "myActualApiKey",
"transactionKey": "myActualTransactionKey"
},
"profile": {
"merchantCustomerId": "Homer Simpson",
"description": "Creating Customer Profile for: Homer Simpson",
"email": "crodgers@newbenefits.com",
"paymentProfiles": {
"customerType": "individual",
"payment": {
"creditCard": {
"cardNumber": "6011000990139424",//Test credit card
"expirationDate": "2028-01"
}
}
}
}
}
}
我不确定我在做什么错。我知道我必须将crossDomain设置为true,但是我一直遇到以下解析错误:
"Unexpected character encountered while parsing value: c. Path '', line 0, position 0."
是什么导致这种情况在浏览器中发生(我使用的是Chrome),而不是在使用ARC时发生?
答案 0 :(得分:0)
我需要对我发送的JSON进行字符串化处理。这将起作用:
$.ajax({
type: "POST",
crossDomain: true,
url: 'https://apitest.authorize.net/xml/v1/request.api',
dataType: "json",
data: JSON.stringify(createCustomerProfileRequest),
data: createCustomerProfileRequest,
success: function (response) {
if (response.dataValue == "Error") {
alert(response.dataDescriptor);
} else {
alert('Successfully sumitted payment!');
}
$("#ccButton").attr("disabled", false);
},
error: function (error) {
alert('Could NOT submit payment!');
$("#ccButton").attr("disabled", false);
}
});