0

i'm new in json cross domain. here is my problem. I want to call php with json cross domain, but still get error. example code to call:

    $(function() {
        var doc = urls;
        $( "#origin" ).autocomplete({
            source: ''+doc+'book/server_book_from.php',
            select: function( event, ui ) 
            {
                $( "#origin" ).val( ui.item.label );
                $( "#take_book_from" ).val( ui.item.code );
                $( "#take_book_from_label" ).val( ui.item.label );
                return false;
            }
        });

        $( "#nation" ).autocomplete({
            source: ''+doc+'book/server_book.php',
            select: function( event, ui ) 
            {
                $( "#nation" ).val( ui.item.label );
                $( "#take_book_to" ).val( ui.item.code );
                $( "#take_book_to_label" ).val( ui.item.label );
                return false;
            }
        });
    });

How can I use json to run a PHP for cross domain??

Thanks.

renku
  • 1
  • First step use the url, second step, make sure the other domain support CORS – epascarello Sep 24 '13 at 01:32
  • You can add a proxy and call ajax in this http://stackoverflow.com/a/11605168/2210993 – andorx Sep 24 '13 at 01:40
  • To get CORS working you need the **server** to send out an access control header. If everyone is allowed, tbis can be very simple. See http://stackoverflow.com/a/3076648/103081 – Paul Sep 24 '13 at 01:43
  • In the code snippet I don't see any JSON. How is JSON involved? With CORS you are better off calling any JSON 'text/plain' instead of 'application/json' to avoid CORS preflight requirements for "non-simple" requests. – Paul Sep 24 '13 at 01:51

1 Answers1

0

The SOP (same origin policy) relies on the protocol, host and port to be the same. CORS (Cross Origin Resource Sharing) allowed a different origin to request a document (see http://enable-cors.org/ for how to do this, and why).

The alternative is JSONP. JSONP will allow you to use callbacks to circumvent SOP.

Martin
  • 6,632
  • 4
  • 25
  • 28