Create a gist now

Instantly share code, notes, and snippets.

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

Embed
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)."])";
?>
@rickytheferris

This comment has been minimized.

Show comment
Hide comment
@rickytheferris

rickytheferris Jul 17, 2014

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

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

@MikSDigital

This comment has been minimized.

Show comment
Hide comment
@MikSDigital

MikSDigital Mar 15, 2015

No description provided.

No description provided.

@samarulrajt

This comment has been minimized.

Show comment
Hide comment
@samarulrajt

samarulrajt Sep 15, 2015

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

This comment has been minimized.

Show comment
Hide comment
@kigh143

kigh143 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

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

@wotta

This comment has been minimized.

Show comment
Hide comment
@wotta

wotta Apr 1, 2016

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

wotta commented Apr 1, 2016

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

@andibastian

This comment has been minimized.

Show comment
Hide comment
@andibastian

andibastian May 3, 2017

thankyou, myproblem solved

thankyou, myproblem solved

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