0

Trying to receive a response from a PHP which is on a different domain to my HTML:

 $.get('getstate.php', {
                email: $('#game-email').val(),
                country: 'DE',
                lang: lang,
                source: 'promotion'
            }, function (data) {
                console.log(data);
             }); 

In chrome I get this error:

XMLHttpRequest cannot load ..... Origin null is not allowed by Access-Control-Allow-Origin.

What do I need to do to achieve this?

George
  • 36,413
  • 9
  • 66
  • 103
user1937021
  • 10,151
  • 22
  • 81
  • 143
  • 1
    http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains – Eli Mar 22 '13 at 11:00
  • surely if you're trying to get `getstate.php` it should be the full path of the url if its located on another domain – chriz Mar 22 '13 at 11:01
  • the fastest way is to proxy the request through the local php server and a curl request – David Fregoli Mar 22 '13 at 11:06

3 Answers3

1

A quick google shows me that this has been answered here many times before... It's not possible with ajax for security reasons, so you will have to either

  1. call another domain from within your PHP script, or
  2. look at JSONP
Community
  • 1
  • 1
msturdy
  • 10,479
  • 11
  • 41
  • 52
0

Try dataType: 'jsonp'
$.get('page.php, {}, callback, "jsonp");

0

a simple PHP proxy from http://jquery-howto.blogspot.co.uk/2009/04/cross-domain-ajax-querying-with-jquery.html

<?php
// Set your return content type
header('Content-type: application/xml');

// Website url to open
$daurl = 'http://feeds.feedburner.com/jQueryHowto';

// Get that website's content
$handle = fopen($daurl, "r");

// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
David Fregoli
  • 3,377
  • 1
  • 19
  • 40