$.ajax({ type: "GET", url: "http://localhost:8000/aa.php",
data: {name: 'Chad'},
dataType: 'jsonp',
jsonp: 'jsonp_callback',
success: function(json) { var tt = json; alert(tt); $("#result").html('submitted successfully'); },
error: function(json) { alert("failure"); $("#result").html('there is error while submit'); } });
/
$jsonp = false;
if ( isset( $_GET[ 'jsonp_callback' ] ) ) {
$_GET[ 'jsonp_callback' ] = strip_tags( $_GET[ 'jsonp_callback' ] );
$jsonp = true;
$pre = $_GET[ 'name' ] . '(';
$post = ');';
} //isset( $_GET[ 'callback' ] )
/* Encode JSON, and if jsonp is true, then ouput with the callback
** function; if not - just output JSON. */
$json = json_encode($_GET[ 'name' ]);
//print( ( $jsonp ) ? $pre . $json . $post : $json );
//print($_GET[ 'jsonp_callback' ].'('.$json.')');
echo $jsonp_callback,$_GET['jsonp_callback'] . "(" . $json . ")";
?>
沒有留言:
張貼留言