Skip to content

Instantly share code, notes, and snippets.

@imcarlosdev
Forked from appastair/jsonp.js
Created November 24, 2015 01:30
Show Gist options
  • Save imcarlosdev/d2c2899a89976c54fdd1 to your computer and use it in GitHub Desktop.
Save imcarlosdev/d2c2899a89976c54fdd1 to your computer and use it in GitHub Desktop.
Cross-domain JSONP Example (jQuery/PHP)
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);
});
);
<?php
header('Content-type: application/x-javascript');
echo $_GET['callback']."([".json_encode($_GET)."])";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment