jsonp跨域请求数据 php后台或者.net后台如何返回数据
作者:本站编辑 发布时间:2015-11-24 来源:本站原创
点击数:
1.php端返回数据代码:
$callback = $_REQUEST['callback'];
// Create the output object.
$output = array('a' => 'Apple', 'b' => 'Banana');
//start output
if ($callback) {
echo $callback . '(' . json_encode($output) . ');';
} else {
echo json_encode($output);
}
2. .net程序段返回的代码格式:
String jsonString = "{success: true}";
String cb = Request.Params.Get("callback");
String responseString = "";
if (!String.IsNullOrEmpty(cb)) {
responseString = cb + "(" + jsonString + ")";
} else {
responseString = jsonString;
}
Response.Write(responseString);