【问题标题】:Accept.js AJAX POST failing for createCustomerProfile endpoint in sandbox沙箱中 createCustomerProfile 端点的 Accept.js AJAX POST 失败
【发布时间】:2019-04-22 18:09:29
【问题描述】:

我能够使用 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 时?

【问题讨论】:

  • 不使用 AJAX 可以得到 Success 的结果吗?
  • 通过 AJAX 发布时,我总是收到 200:成功的 HTTP 代码。但是,我收到的错误是对 200 的响应。

标签: ajax authorize.net


【解决方案1】:

我需要对我发送的 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);
            }
        });

【讨论】:

    猜你喜欢
    • 2019-11-06
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2017-03-17
    • 1970-01-01
    • 2012-08-31
    相关资源
    最近更新 更多