javascript - Phonegap 和 Restful 网络服务

标签 javascript web-services cordova

我想从返回 xml 的 Restful Web 服务中检索数据。我正在使用phonegap。

我已经尝试过这段代码,它在 InternetExplorer 上给了我结果,但在我的手机间隙应用程序上却没有!

    <!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"';

关于javascript - Phonegap 和 Restful 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9376665/

相关文章:

android - 在 Phonegap 应用程序中使用 Android 后退按钮退出全屏 HTML5 视频播放器

android - cordova 插件 rm cordova-plugin-whitelist 不会更改 config.xml 因此它将在构建时重新添加

javascript - 使用 javascript 设置的跨度背景颜色未打印

javascript - React-hooks-form - 迭代字段数组,其中使用 useState 设置其中一个字段

javascript - JavaScript 函数中的 JSON 数据渲染

javascript - 在 Meteor v1.7.0.3 中添加和使用 jQuery 插件

python - Flask 和/或 Tornado - 处理对外部网络服务的耗时调用

web-services - 如何找到我的密码?

web-services - 在哪里使用网络服务

javascript - Meteor 具有 blaze(网络)和 Angular(移动)