ios - 将 JSON 拉入 PhoneGap 会导致 404

标签 ios json cordova expressionengine

我正在尝试为 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/

相关文章:

ios - MapView 自动更改区域

ios - 这个 Int32 初始化器能返回 nil 吗?

json - 如何在 Go 中将 JSON 解码为接口(interface){}?

使用 Cordova 的 Facebook Android Key Hash

cordova - 相机、位置和联系人API不支持phonegap

ios - 谁能用 MKMapView::mapRectThatFits 解释这些不准确之处

ios - 使用可区分数据源时如何处理空状态 - UICollectionViewDiffableDataSource?

javascript - JSON、Highcharts 和 Coldfusion json 数据

json - 将 JSON.parse 委派给网络 worker 是否值得(在 Chrome 扩展/FF 插件中)?

ios - iOS中的AutoHideSplashScreen不会使用非index.html页面在Phonegap 2.5中隐藏启动画面