Create a gist now

Instantly share code, notes, and snippets.

@appastair /jsonp.js
Last active Jul 12, 2017

What would you like to do?
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)."])";
?>

My question is how to manipulate the variables in PHP? anything I do just seems to break it...

No description provided.

1,'email'=>'sam@example.com'); echo $_GET['callback'] . '(' . "{'success' : '1' , 'user' : ".json_encode($data)." }" . ')';die(); ?>

kigh143 commented Mar 4, 2016

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

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