简体   繁体   English

发布请求永不返回获取api js

[英]post request never returning fetch api js

Hello guys I'm trying to make a post request using js fetch api but the problem it's not returning. 大家好,我正在尝试使用js fetch api发出发布请求,但问题没有返回。 It never enters the callback in the then function. 它永远不会在then函数中输入回调。 Can somebody tell me what is it that is going wrong 有人可以告诉我这是怎么回事

fetch('http://ready.buzlin.com/buzlinApp/checkout/checkout.php', {
              method: 'POST',
              headers: {
                  'Content-Type': 'application/json',

              },
              body: s
          }).then((response) => {
              console.log("ok");
          });

If I make the same call using postman it works 如果我使用邮递员拨打相同的电话,则可以正常工作

在此处输入图片说明

This is a CORS problem, a security measure adopted by browsers (which explains why you could do it via Postman). 这是CORS问题,是浏览器采用的一种安全措施(这说明了为什么可以通过Postman做到这一点)。

Basically, your browser sends a preflight request to the server to know what it is expecting, and the server isn't returning your origin as an acceptable one (Access-Control-Allow-Origin Header). 基本上,您的浏览器向服务器发送预检请求以了解其期望,并且服务器不会将您的来源作为可接受的来源返回(Access-Control-Allow-Origin标头)。

This API probably does not support CORS. 该API可能不支持CORS。 That means your request will only work if made from server-side, secure browsers will not allow it. 这意味着您的请求仅在从服务器端发出时才起作用,安全的浏览器将不允许它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM