2012-10-26 30 views
2

我有一個index.html ajax調用一個web服務(ASP.NET),當我在bigrock服務器(我有一個域)上部署它時工作正常。Phonegap + Webservice

$.ajax({ 
     type: "POST", 
     url: "myurl/mywebservice.asmx", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (msg) { 
      alert("success"); 
     }, 
     error: function (msg,status) { 
      $('#demo').html("status is "+status+" . Msg is "+msg.d.responseText); 
      //attribute for responsetext might be wrong here but in my application it is correct as i am using different system ryt now. 
     } 
    }); 

但是當我用的PhoneGap的網上拉鍊做出的apk我從HTML,CSS,JS,web.config中,幾級Android應用程序並安裝到設備上...沒有出現。它顯示我沒有responseText ajax錯誤。

我在想什麼?

回答

1

當你拉上你的資產提交的PhoneGap構建,你需要包括一個config.xml file,並指定類似於

<access origin="https://your.domain.com" /> 

這准入政策將指示PhoneGap的允許與通信您服務器。

+0

這個dnt幫助我...而且我無法調試它.. 。任何想法如何調試設備中安裝的應用程序.. –

+2

PhoneGap有一個調試服務可在http://debug.phonegap.com/。這由[weinre]提供支持(http://people.apache.org/~pmuellr/weinre/docs/latest/)。有像[spotneedle](http://spotneedle.com)和[jsconsole](http://jsconsole.com)這樣的外部服務可能也有幫助。 – 2012-10-27 14:20:00

+0

我試着通過debug.phonegap.com進行調試......不幸的是,移動設備在控制檯中沒有輸出,也沒有顯示設備......我想我的應用程序無法從我的設備訪問互聯網......這是可能的? –

0

當您的應用程序使用PhoneGap部署到設備時,您的「主頁」位置將成爲本地設備上的文件系統。

這意味着任何ajax調用都是需要進一步配置才能正確設置的跨域調用。

this question for potential answer

+0

我有關於跨域的想法,但我dnt知道如何解決它...而且我們也使用在線phonegap拉鍊。 –

+0

如果您控制服務,這也提供了一個很好的解決方案: http://stackoverflow.com/questions/3010028/wcf-rest-with-jquery-ajax-removing-working-around-same-origin-policy?rq= 1 –

+0

使用,我可以解決我的問題,但不是在我的移動設備上....我正在尋找我的Android設備的解決方案... –