我正在尝试为 PhoneGap 设置一个 JSON 查询,该查询会提取通过 Expression Engine template 创建的 JSONP .如果我直接导航到我的 JSON 页面,http://www.lcbcchurch.com/mobileJSON/homeslideshow ,我得到了正确的输出。尝试将其拉入我的 iPhone 应用程序 (phonegap) 是另一回事。它说在控制台中找不到它(404)。我检查了所有链接,我认为我正确执行了回调方法,但似乎没有任何效果。请帮忙。这是我的 EE 插件代码:
{exp:json:entries channel="slideshow" jsonp="yes" callback="{segment_3}" content_type="application/javascript"}
和应用程序代码:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Ajax Sample</title>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$.ajax({
url: "http://www.lcbcchurch.com/mobileJSON/homeslideshow/results",
dataType: "jsonp",
jsonp: false
});
function results(data) {
console.log(data);
}
</script>
</head>
<body>
<div id="main">
</div>
</body>
</html>
最佳答案
您是否确定已将 Xcode 项目中的所有外部主机列入白名单?另外你的ajax调用看起来有点不对劲...你添加了回调,就像目录与参数一样..如果你删除它并且只让成功函数调用它就可以工作。
使用phonegap,您无需担心跨域,您所需要做的就是通过向phonegap.plist 文件中的externalHosts 添加新值,将xcode 项目中的所有域列入白名单 - 将 key 设置为“websites”并'*' 的值,这是一个包罗万象的东西。
$.ajax({
url: "http://www.lcbcchurch.com/mobileJSON/homeslideshow",
dataType: "json",
success:function(data){
results(data);
}
});
function results(data) {
for(var i = 0; i<data.length;i++){
// this will log all of the images url
console.log(data[i].image); // just access the part you want by it's name.
}
}
关于ios - 将 JSON 拉入 PhoneGap 会导致 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316974/