Accept.js AJAX POST失败,因为沙箱中的createCustomerProfile端点

问题描述 投票:0回答:1

我能够使用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": "[email protected]",
      "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时?

ajax authorize.net
1个回答
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);
            }
        });
© www.soinside.com 2019 - 2024. All rights reserved.