1

我正在尝试使用AxiosPardot FormHandler发布请求,但无法发送数据。Pardot 引发 CORS 错误。我做了一些搜索,看起来pardot表单没有获取来自 Axios/Ajax 的任何数据。因此,为了防止这种情况,我尝试将其发送formdata如下...

submit(){
  var bodyFormData = new FormData();
  bodyFormData.append('LastName', "test");
  bodyFormData.append('FirstName', "test");
  bodyFormData.append('email', "example@gmail.com");

  axios({
    method: 'post',
    url: 'https://go.pardot.com/l/pardotformurl',
    data: bodyFormData,
    headers: {'Content-Type': 'multipart/form-data' }
  })
  .then(res => {
      console.log(res);
  })
  .catch(err => {
      console.log(err);
  })

},

我发送它formdata但仍然是一个错误。顺便一提。如果我不使用 axios 并将其作为 a 发送,<form actions="/" method="post" />那么它就没有问题。但是,我需要axios用于这项工作。那么有没有办法解决这个问题..?

4

1 回答 1

0

Pardot doesn't support submitting data to form handlers via axios, fetch or XHR. When attempting to submit data to a form handler using that, you will likely see errors like:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '{page from which form handler should be getting submitted on client's website}' is therefore not allowed access.

This is what's known as CORS (Cross-Origin Resource Sharing). Pardot doesn't currently support CORS or JSONP for form handlers. It is possible to simulate a JSONP response by setting the Success and Error URLs for the form handler to be JavaScript URLs that execute Success and Error callbacks, respectively.

于 2020-11-16T00:09:06.090 回答