John PHP John PHP - 1 year ago 81
Javascript Question

making cross domain request using ajax

This is probably a famous question, I have seen lot of questions similar to this on Google and so as well. There is a web server on my LAN at
on machine

I have a
page on machine
, this HTML page wants to make
ajax request
to web server at
, I made the page and tried this and got

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://XXXXXXXXXXX/ajax_info.txt. (Reason: CORS header 'Access-Control-Allow-Origin' missing)

Question :

  1. Is there by any chance I can enable this in mozilla ?

  2. How can we make request to
    facebook, twitter, jquery
    lib servers via ajax if cross domain is disabled ?

  3. Can I add
    to my vanilla ajax request ?


Answer Source

You put

header('Access-Control-Allow-Origin: *');  

on machine A

If you want to be more secure you can add your domain in place of the * - for example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download