【问题标题】:Cross-domain JavaScript: No 'Access-Control-Allow-Origin' header is present跨域 JavaScript:不存在“Access-Control-Allow-Origin”标头
【发布时间】:2018-09-29 12:35:28
【问题描述】:

我尝试向另一个开发人员构建的 API 进行 AJAX HTTP POST。我为此使用 JQuery,API 在 PHP 中。但是,我在控制台中收到以下错误:

对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头

我的 HTML:

<form>
  <input id="target" type="text" value="Field 1">
</form>

我的 Javascript/JQuery:

$("#target").on("click", checkemail);

function checkemail(){
  $.ajax({
    type: 'POST',
    url: 'https://test.api.planitcommander.nl/funnel_webhooks/emailExists',
    data: JSON.stringify({"email": "rj@xxxx.nl"}),
    contentType: "application/json",
    dataType: 'json'
    })
  .fail (function(data){
    console.log(data);
    })
}

我的 JQuery 代码是否有错误,或者我应该向 API 开发人员寻求解决方案?

似乎后者来自:Javascript CORS - No 'Access-Control-Allow-Origin' header is present

【问题讨论】:

标签: javascript jquery


【解决方案1】:

请试试这个

function checkemail(){
  $.ajax({
    type: 'POST',
    url: 'https://test.api.planitcommander.nl/funnel_webhooks/emailExists',
    data: JSON.stringify({"email": "rj@xxxx.nl"}),
    contentType: "application/json",
    dataType: 'jsonp'
    })
  .fail (function(data){
    console.log(data);
    })
}

请看https://vverma.net/fetch-any-json-using-jsonp-and-yql.html

【讨论】:

  • 请为您的答案添加某种解释
猜你喜欢
  • 2015-07-18
  • 2016-10-30
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 2019-08-15
  • 2017-02-21
  • 2015-09-28
  • 2016-10-30
相关资源
最近更新 更多