0

I need to make a cross domain ajax call to a server I own but the problem is that the request must come from the client not the server so proxies wont work for me. Our server will be behind a vpn so it won't be able to reach the internet but the client will be able to so we wanted to do a call home from the client to our metrics server to validate a product key.

My remote domain has a php script that simply writes either a 0, 1, or 2. I need my javascript to read this value in and react to it.

I want to do something simple like this but clearly it won't work. Any suggestions?

            $.ajax({
                url: callHomeUrl,
                type: 'GET',
                success: function(res) {
                    document.write($(res.responseText).text());
                }
            });
FuegoFingers
  • 2,181
  • 6
  • 27
  • 36

1 Answers1

0

You can use a JSONP style implementation for that to get access to your server which works across all browser without CORS!

Example -

var script=document.createElement('script'):
   script.type='text/javascript'; script.src='path/to/the/file';
document.getElementsByTagName('head')[0].appendChild(script);

Note that the file in the server should output the javascript function along with any relevant data.

spaceman12
  • 1,039
  • 11
  • 18