gpt4 book ai didi

javascript - Phonegap 和 Restful 网络服务

转载 作者:行者123 更新时间:2023-11-28 09:59:38 24 4
gpt4 key购买 nike

我想从返回 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com