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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

It’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