php代码
<?php
$data = trim(api_get('threads',array(),'JSON'));
echo $_GET['jsonp_callback'] . '(' . $data . ');';
?>
js代码
<script>
$.ajax({
url: "https://abc.secure.tttt.com/",
data:{},
dataType: 'jsonp',
cache: false,
crossDomain: true,
jsonp : "jsonp_callback",
success: function(params){
console.log('showInbox');
//console.log(JSON.parse(params));
showInbox(params);
},
error: function (xhr, textStatus, thrownError) {
console.log('Inside showInbox ajax failure');
console.log(xhr.status);
console.log(textStatus);
console.log(JSON.stringify(xhr));
console.log(thrownError);
}
});
这工作正常,如果 API 提供 json 数据并且如果出现错误,则显示语法错误:
Timestamp: 5/9/2013 4:28:24 PM
Error: SyntaxError: syntax error
Source File: https://abc.secure.tttt.com/?jsonp_callback=jsonp1368095332316&_=1368097103961
Line: 1
Source Code:
<!DOCTYPE html>