Phonegap and restful web service
Phonegap and restful web service
我想从返回xml的restful Web服务中检索数据。我在用phonegap。
我试过这个代码,它在InternetExplorer上给了我结果,但在我的手机gap应用程序上没有!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PhoneGap</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" charset="utf-8" src="js/Config/phonegap-0.9.3.js"></script>
<link rel="stylesheet" href="css/jquery/jquery.mobile-1.0a1.min.css" />
<link rel="stylesheet" href="css/Style.css" />
<script src="js/Config/jquery-1.4.3.min.js"></script>
<script src="js/Config/jquery.mobile-1.0a1.min.js"></script>
<script type="text/javascript">
function getDescription() {
var url = 'http://localhost/prestashop/api/customers/2';
req = new XMLHttpRequest();
req.onreadystatechange = processRequest;
req.open("GET", url, true);
req.send(null);
}
function processRequest() {
if (req.readyState == 4) {
if (req.status == 200) {
alert ( "Not able to retrieve description+"+req.responseText );
parseMessages();
} else {
alert ( "Not able to retrieve description+"+req.responseText+"vide" );
}
}
}
function parseMessages() {
response = req.responseXML.documentElement;
itemDescription = response.getElementsByTagName('lastname')[0].firstChild.data;
alert ( itemDescription );
}
</script>
</head>
<body>
<button onClick="getDescription()">Ajax call</button>
</body>
</html>
它返回req.status=0!!
尝试
var url = 'http://localhost/prestashop/api/customers/2?PHP_AUTH_USER="password"&ws_key="login"';
尝试更改此行:
if (req.status == 200) {
进入:
if (req.status == 200 || req.status == 0) {
在从file://protocol运行的移动设备上,当请求成功时,您通常会得到0的状态。
您在Chrome中会得到什么结果?Chrome和Android浏览器(以及Safari和BlackBerry浏览器)都基于WebKit。
您是否已将访问源添加到phonegap.xml文件中?
有没有什么特别的原因,你不使用jQueryMobile的AJAX?您是否能够使用jQM获得成功的响应?
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 在Web应用程序中使用Highcharts javascript
- windows 8 wcf web service (localhost/intranet)
- 将通过Ajax(和Web Service方法)获得的数组转换为javascript数组
- ASMX Web Service from Javascript
- How to POST javascript Blob to JAX-WS Web service
- 使用带有 AngularJS(angular-websocket-service)和 Spring Boot 的 Web
- JAX-RS Web Service 通过浏览器工作,但不通过 XMLHTTPRequest
- 来自链接函数的Restful web service调用
- 使用Javascript和AJAX到Web Service的浏览器内FIFO队列
- Phonegap and restful web service
- 在ASP中仅使用jquery和Web Service从客户端上传图像
- Service Worker在渐进式Web应用中没有自动更新
- 如何在angular js中使用web worker来调用service
- 从javascript发送对象列表到Spring web service的结果是空对象
- JavaScript communicate with web Service
- 为Restful Web Service构建JSON配置的正确方法
- .NET Web Service 性能不佳(使用 MVC3 考虑切换到 WCF)
- 使用 Angular 2 Http 从 REST Web Service 获取数据
- AngularJS RESTful Web Service -向表中添加行而不刷新