choquo
11/24/2015 - 1:30 AM

Cross-domain JSONP Example (jQuery/PHP)

Cross-domain JSONP Example (jQuery/PHP)

<?php
header('Content-type: application/x-javascript');
echo $_GET['callback']."([".json_encode($_GET)."])";
?>
jQuery(function($){
    $.ajax({
        type: 'GET',
        url: '//remote.org/jsonp.php',
        data: {
            field: 'value'
        },
        dataType: 'jsonp'
        crossDomain: true,
    }).done(function(response){
        console.log(response);
    }).fail(function(error){
        console.log(error.statusText);
    });
);