1

也许我用错了。我不知道。我所知道的只是它与 appMobi 附带的 XHR.js 相关。我拥有 2 天前网站上的最新版本。我正在 Macbook Pro 上开发。我正在尝试使用 XDK 在本地进行测试,并通过本地 Wifi/使用 Android 平台使用 HTC Evo 3D 在任何地方进行测试。以及我正在使用 iPhone 4S 和 iPad2。每次都是一样的结果。

我在控制台调试窗口中看不到任何错误。我看到的只是“RemoteBridge”或“RemoteBridge2”这两个词。我的脚本很简单。只是一个简单的基于 jQuery 的 $.ajax 帖子和一个小 html。虽然我会在发布它时更改它,因为我不希望它通过公共论坛可见,但该 URL 是一个有效的 URL,并删除了一个有效的 JSON 对象作为其输出。所以我需要输入,我不知道从哪里开始,因为我的应用程序需要大量动态更新的动态数据。据称我所要做的就是包含 xhr.js 并且我的标准 jQuery 应该可以工作。

无论如何,这是我的代码。

索引.html

<!DOCTYPE HTML>
<html>
   <head>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Untitled Document</title>
      <link rel="stylesheet" media="all" href="./src/global.css">
   </head>
   <body>
      <div id="header">
         <div id="logo"></div>
         <div id="coname">COMPANY</div>
      </div>
      <div id="content"></div>
      <div id="footer">
         <div id="advert"></div>
      </div>   
      <script type="text/javascript" charset="utf-8" src="./src/appmobi.js"></script>
      <script type="text/javascript" charset="utf-8" src="./src/xhr.js"></script>
      <script type="text/javascript" charset="utf-8" src="./src/jquery-1.7.2.min.js"></script>
      <script type="text/javascript" charset="utf-8" src="./src/global.js"></script>
   </body>
</html>

以及 global.js 的内容

// This event handler is fired once the AppMobi libraries are ready
function onDeviceReady() {
    //use AppMobi viewport to handle device resolution differences if you want
    //AppMobi.display.useViewport(768,1024);

    //hide splash screen now that our app is ready to run
    AppMobi.device.hideSplashScreen();
}

//initial event handler to detect when appMobi is ready to roll
document.addEventListener("appMobi.device.ready",onDeviceReady,false);

$(document).ready(function()
{
/*
   var request = $.ajax({
      url: "http://this.url-has-been-changed.net/geo/suggest",
      type: "POST",
      data: {"entry" : "951"},
      dataType: "json"
   });
   request.done(function(data){$('#advert').append('done');});
   request.fail(function(data){$('#advert').append('fail');})
   request.error(function(data){$('#advert').append('error');})
   request.complete(function(data){$('#advert').append('complete');})
   request.success(function(data){$('#advert').append('success');})
   */



   $.ajax({
      type: 'POST',
      url: "http://this.url-has-been-changed.net/geo/suggest?entry=951",
      success: function(data){$('#advert').html('success');},
      error : function(data){$('#advert').html('failed');},
      complete : function(data){$('#advert').html('complete');},
      dataType: "json"
   });

});

发现包含的所有其他文件均来自 appmobi

4

1 回答 1

3

克里斯,

有几件事可以帮助您解决这个问题。

  1. 确保您引用 appMobi.js 和 XHR.js 来自
    http://localhost:58888/_appMobi

为了利用 JavaScript API 桥命令 (http://www.appmobi.com/documentation/jsAPI.html)。

  1. 等到“appMobi.device.ready”事件触发后再使用这些 JavaScript API 桥接命令。在您的情况下,XHR.js 库实际上正在将 XMLHttp 调用转换为本机 AppMobi.device.getRemoteData 调用。

试试这个 index.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<!--
<link rel="stylesheet" media="all" href="./src/global.css">
-->
</head>
<body style="background-color:white;">
<div id="header">
<div id="logo"></div>
<div id="coname">COMPANY</div>
</div>
<div id="content"></div>
<div id="footer">
<div id="advert"></div>
</div>   
<script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/appmobi.js"></script>
<script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script>
<script type="text/javascript" charset="utf-8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="global.js"></script>
</body>
</html>

连同这个 global.js

// This event handler is fired once the AppMobi libraries are ready
function onDeviceReady() {
//use AppMobi viewport to handle device resolution differences if you want
//AppMobi.display.useViewport(768,1024);

//hide splash screen now that our app is ready to run
AppMobi.device.hideSplashScreen();

$.ajax({
type: 'POST',
url: "http://this.url-has-been-changed.net/geo/suggest?entry=951",
success: function(data){$('#advert').html('success');},
error : function(data){$('#advert').html('failed');},
complete : function(data){$('#advert').html('complete');},
dataType: "json"
});
}

//initial event handler to detect when appMobi is ready to roll
document.addEventListener("appMobi.device.ready",onDeviceReady,false);

XHR.js 和 appMobi.js 库由包装应用程序本身提供,以便“侦听”需要本机级别功能的 JavaScript 调用。例如,允许您发出跨域数据请求的 AppMobi.device.getRemoteData 命令。为方便起见,XHR.js 库将 XmlHTTP 调用转换为 AppMobi.device.getRemoteData 命令。

有关 JavaScript API 的更多信息,请查看以下文档:

http://www.appmobi.com/documentation

于 2012-05-21T18:55:09.227 回答