在localhost上不允许使用Cordova / jQuery Mobile origin null

时间:2012-08-12 15:03:07

标签: jquery jquery-mobile cordova

我正在构建一个基于Cordova(Phonegap)和jQuery Mobile的Web应用程序。由于我使用Ajax获取数据,因此我在我的Web服务器提供的动态内容中添加了Access-Control-Allow-Origin标头。这很有效。

由于我不想使用单个模板布局,因此我创建了在页脚导航栏中链接的多个文件。它们位于localhost(手机)上的/ www文件夹中。每当我使用导航栏中的链接到其中一个页面时,我都会收到Origin null is not allowed by Access-Control-Allow-Origin.错误。我该如何解决这个问题?

<div data-role="footer" data-position="fixed">
  <div data-role="navbar">
    <ul>
      <li><a data-icon="star" href="start.html">start</a></li>
      <li><a data-icon="grid" href="list.html">list</a></li>
      <li><a data-icon="alert" href="alert.html">alert</a></li>
    </ul>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

选项1: 您需要将 $ .support.cors $。mobile.allowCrossDomainPages 值设置为true。

“您在Phone Gap jQuery Mobile应用程序中访问跨域页面的能力由两个关键因素控制: $ .support.cors $ .mobile.allowCrossDomainPages ,也可能受到PhoneGap后期版本中白名单功能的影响。“

http://jquerymobile.com/test/docs/pages/phonegap.html

了解详情

选项2: 我猜您可能不想使用它,但是可以通过对您的标记使用 data-ajax =“false”来关闭Ajax链接行为。