2012-05-19 15 views
1

也許我正在與它一起工作錯了。我不知道。我所知道的是它專門與appMobi附帶的XHR.js做了一些事情。我有兩天前在那裏的最新版本。我正在開發Macbook Pro。我試圖用XDK在本地進行測試,並通過使用Android平臺的HTC Evo 3D在任何地方通過本地Wifi /測試進行測試。以及我正在使用iPhone 4S和iPad2。每次都有相同的結果。appMobi xhr.js丟失jquery帖子返回數據

我在控制檯調試窗口中看到沒有錯誤。我看到的只是「RemoteBridge」或「RemoteBridge2」。我的腳本很簡單。只是一個簡單的基於jQuery的$ .ajax文章和一個小的HTML去與它。儘管我會在發佈URL時改變它,但我不希望它通過公共論壇顯示,但它是一個有效的URL,並將有效的JSON對象作爲其輸出。所以我需要輸入,我不知道該從哪裏下去,因爲我的應用程序需要大量動態數據,這些動態數據可以隨時更新。據稱,我所要做的只是包含xhr.js,而我的標準jQuery應該可以工作。

無論如何,這裏是我的代碼。

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

回答

3

克里斯股票,

剛有幾件事可以幫助你理解這一點。

  1. 確保您以利用的JavaScript API橋命令(http://www.appmobi.com/documentation/參考appMobi.js和XHR.js從
 
    http://localhost:58888/_appMobi 

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命令。

http://www.appmobi.com/documentation

有關JavaScript API的更多信息,請查看文檔