Skip to content

Instantly share code, notes, and snippets.

@appastair
Last active August 23, 2020 17:52
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save appastair/3865796 to your computer and use it in GitHub Desktop.
Save appastair/3865796 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)."])";
?>
@wotta
Copy link

wotta commented Apr 1, 2016

try to add ?callback=? ( don't know if it will work )

@andibastian
Copy link

thankyou, myproblem solved

@Mutale85
Copy link

I wish to submit that this helped me. I was trying an API i made.

@appastair
Copy link
Author

I'm happy to hear it, @Mutale85 - all the best! 👋 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment