高级REST客户端到jQuery请求

时间:2017-08-11 16:52:44

标签: javascript jquery ajax rest web

我有一个由客户端设置的ARC,一切似乎在ARC和后端都运行正常,但我看不出我在jQuery中做错了什么

这是ARC测试

enter image description here

这是我的jQuery代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script> 
  <script>
    let urlBase = 'http://54.210.29.209';
    let urlEnterEmail = '/api/v1/users/checkEmail';

    $(document).ready(function() {

      $.ajax(
        {
          method: "POST",
          crossDomain: true,
          url: urlBase + urlEnterEmail,
          xhrFields: {withCredentials: true},
          headers: {
            "Access-Control-Request-Headers": "x-requested-with",
            "Content-Type": "application/json",
            "Platform": "web",
            "Build": 2
          },
          contentType: "application/json; charset=utf-8",
          dataType: 'json',
          data: {"email": "john@doe.com"}
        }
      )
      .done(function (response) {
        console.log('done!');
        console.log(response);
      })
      .fail(function (xhr, status) {
        console.log('fail!!!');
        //console.log(xhr); 
        console.log(status);
      });

    });
  </script>
</head>
<body>

</body>
</html>

最后,错误

enter image description here

我读了一些关于CORS的内容,但它没有用。我找到的资源如下,但我仍然不知道我是否有问题或后端代码。

How to get a cross-origin resource sharing (CORS) post request working

https://www.html5rocks.com/en/tutorials/cors/

0 个答案:

没有答案