gpt4 book ai didi

javascript - PhoneGap 和 PrestaShop 网络服务

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

我想从我的 PrestaShop 网站的 Web 服务(返回 XML)检索数据。我使用PhoneGap Android。我尝试了这段代码,它在 Internet Explorer 上提供了良好的结果,但在我的 PhoneGap 应用程序上却没有。

<!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>

我也尝试过这段代码,但我遇到了同样的问题。

<!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 src="jquery.form.js"></script>


<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "http://localhost/prestashop/api/customers/2",
//dataType: "xml",
success: parseXml
});

function parseXml(xml) {alert("a");
$(xml).find("customer").each(function() {alert("b");

$("#dropdownlist").append("<hr>"+$(this).find("lastname")[0].firstChild.data+"<hr>");
});
}

});
</script>
</head>

<body>
<div id="dropdownlist" />
</body>
</html>

最佳答案

可能是因为您没有授权访问外部主机。

您是否在 /res/xml/PhoneGap.xml 中添加了此内容

<?xml version="1.0" encoding="utf-8"?>
<phonegap>
<access origin="*"/>
<log level="DEBUG"/>
</phonegap>

在执行任何代码之前,您可能还需要等待 PhoneGap 准备就绪

// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
//
function onDeviceReady() {
// YOU CODE
}

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

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