error accessing php script from another site.

Status
Not open for further replies.

amglbx10

New Member
Messages
1
Reaction score
0
Points
1
i am trying to access one of my php scripts from another site via JS and get this error in the console

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://blablabla/1.php?a=a. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

how do i fix this

thanks
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Hi,

A security feature in modern web browsers means that JavaScript can only be used to access external pages if they have permission to do so, through setting the "Access-Control-Allow-Origin" header. This is to prevent users from maliciously using JavaScript to carry out an action on another website, without the user's consent.

For example, if I had a page on "website1.x10.mx", that connected to "website2.x10.mx" through JavaScript alone, I would need to set an Access-Control-Allow-Origin header on "website2.x10.mx" of "website1.x10.mx", so it has permission to retrieve data.

Therefore, you can solve this problem by either having your external PHP script serve the "Access-Control-Allow-Origin" header, or you could retrieve the data using PHP instead. ;)

Thank you,
 
Status
Not open for further replies.
Top