简体   繁体   中英

Javascript XMlHttprequest to another domain

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?

It's not possible to get around it from the client side in your JavaScript/HTML.

The CORS restrictions are enforced by your browser and are based on the presence of particular Access-Control-* headers in the server response, and the values of those response headers.

If a server doesn't send an Access-Control-Allow-Origin response header for a resource, then you won't be able to fetch it from JavaScript in a Web app. No changes you make to your XHR requests will fix that (eg, 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 "No 'Access-Control-Allow-Origin' header is present on the requested resource" etc here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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