admin管理员组文章数量:1389777
I am making a cross site http request using the Javascript XMlHttprequest api to send and retrieve data in post method. The purpose is to send sms using this service provided by the 3rd party. However I am not able to do, as this is not allowed by the browser and receiving the following error response "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at .php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)."
Is it possible to achieve this using html and javascript?
I am making a cross site http request using the Javascript XMlHttprequest api to send and retrieve data in post method. The purpose is to send sms using this service provided by the 3rd party. However I am not able to do, as this is not allowed by the browser and receiving the following error response "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://trans.smsfresh.co/api/sendmsg.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)."
Is it possible to achieve this using html and javascript?
Share Improve this question edited Aug 25, 2017 at 18:52 sideshowbarker♦ 88.6k30 gold badges215 silver badges212 bronze badges asked Jan 27, 2017 at 17:51 asim choudhuryasim choudhury 632 silver badges6 bronze badges1 Answer
Reset to default 6It’s not possible to get around it from the client side in your JavaScript/HTML.
The same-origin restrictions are enforced by your browser but can be relaxed by Access-Control-*
CORS headers in the server response.
If a server doesn’t send an Access-Control-Allow-Origin
response header for a resource, you won’t be able to fetch it from JavaScript in a Web app. No changes you make to your requests will fix that (e.g., no additional request headers you might add on the client side will help).
For details see the MDN HTTP access control (CORS) article.
And see Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not? etc here.
本文标签: Javascript XMlHttprequest to another domainStack Overflow
版权声明:本文标题:Javascript XMlHttprequest to another domain - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744695893a2620273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论