$.ajax() 在 phonegap 上 [英] $.ajax() on phonegap

查看:27
本文介绍了$.ajax() 在 phonegap 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁知道 githubphonegap$.ajax() 的一个例子?我读过 JSONP 或 CORS,但我只从 Twitter 请求数据.

Anyone know an example of phonegap with $.ajax() in github for Android? I have read of JSONP or CORS but I have worked only requesting data from Twitter.

我只需要获取我的数据服务器.

I just need to get my data server.

推荐答案

通过 jquery mobile 非常容易.您可以使用普通的 Ajax 和一点点 JSON 来完成您的工作.我完成了 php 服务器.这里是示例代码,

It is very easy through jquery mobile. You can do your job with normal Ajax and little bit of JSON. I done with php server. Here the sample code,

通过jquery向服务器发送请求.

Sending request to server through jquery.

$.ajax({
          url: <your Server URL>,
          dataType: 'jsonp',
          jsonp: 'jsoncallback',
          timeout: 5000,
          success: function(data, status){
                             /*Process your response here*/
                        }
       });

在php服务器文件中,

In php server file,

<?php
$data="I am sending response to you";

/*you have to mention this callback compulsory*/

echo $_GET['jsoncallback'] . '(' . json_encode($data) . ');';
?>

这篇关于$.ajax() 在 phonegap 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆