通过Phonegap连接到HTTP服务器 [英] Connect to HTTP server via Phonegap
本文介绍了通过Phonegap连接到HTTP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个服务器组件通过HTTP连接到远程服务器,并得到一些响应。
I have server component which connects to a remote server via HTTP(s) and gets some response. Can I connect to such a server side code in a java plugin if I am using Phonegap for Android ?
推荐答案
我可以使用xmlHttpRequest方法来获取服务器或
的响应,您可以使用 jquery 插件 http:// jquery.com/ ,并使用jquery的ajax函数。
You can use xmlHttpRequest method of javascript to get the response from server or you can use jquery plugin http://jquery.com/ in your app and play with ajax function of jquery.
$.ajax({
url:'stringURL',
beforeSend: function(x) {
x.setRequestHeader('Authorization','username/pwd');
},
dataType:"xml",
contentType:'application/xml',
timeout:10000,
type:'POST',
success:function(data) {
alert(data);
},
error:function(XMLHttpRequest,textStatus, errorThrown) {
alert("Error status :"+textStatus);
alert("Error type :"+errorThrown);
alert("Error message :"+XMLHttpRequest.responseXML);
}
});
这篇关于通过Phonegap连接到HTTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文