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)."])"; | |
?> |
samarulrajt
commented
Sep 15, 2015
1,'email'=>'[email protected]');
echo $_GET['callback'] . '(' . "{'success' : '1' , 'user' : ".json_encode($data)." }" . ')';die();
?>
hey , am tying to use the jsonp but it still shows this error <-----because it violates the following Content Security Policy directive--->
anyone please help me
try to add ?callback=? ( don't know if it will work )
thankyou, myproblem solved
I wish to submit that this helped me. I was trying an API i made.
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