有人知道在Github上关于在Android上使用phonegap和$.ajax()
的例子吗?我只是从Twitter请求数据,所以我已经阅读了JSONP或CORS的内容。
我只需要获取我的数据服务器。
使用jQuery Mobile非常容易。您可以使用普通的Ajax和少量JSON来完成工作。我使用php服务器完成了此操作。以下是示例代码:
通过jQuery向服务器发送请求。
$.ajax({
url: <your Server URL>,
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
/*Process your response here*/
}
});
<?php
$data="I am sending response to you";
/*you have to mention this callback compulsory*/
echo $_GET['jsoncallback'] . '(' . json_encode($data) . ');';
?>
请查看此URL。它将帮助您从数据服务器加载数据。