Last active
August 23, 2020 17:52
-
-
Save appastair/3865796 to your computer and use it in GitHub Desktop.
Cross-domain JSONP Example (jQuery/PHP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
I wish to submit that this helped me. I was trying an API i made.