2

Am working in jQuery mobile and PhoneGap. Currently am facing a big issue which still existing. I searched and applied lot of methods but still problem existing. My Problem is when I call an API its timeout after 10 Seconds. So its not getting result in iPhone versions.. but Its return result in Android (In the case of android its also shows timeout but i get its result.)

I Tried Timeout methods in jQuery Ajax call.. but :-(

Here is my code ;

function proceed_payment(){
var cardholder_= $('#input_Cardholder_name_').val();
var card_num_ = $('#input_CreditCard_').val();
var payment_ =$('#card_type_').val();
var cvv2_=$('#input_cvv2_').val();
var url;

if(showmond_value==0)
{
    url='https://www.sample.com/json/save_pament.php?json=1& reserv_num='+reservation_number+'&callback='+reservation_carcompany+'&cardholder='+cardholder_+'&payment='+payment_+'&card_num='+card_num_+'&card_cvv2='+cvv2_+'&card_expire_mon='+expire_month+'&card_expire_year='+expire_year+'&org_deposit='+sCarDeposit+'&org_cur='+currency+'&mond='+company_Show_mond+''
}

$.ajax({  
  url:url,
  data:'',
  contentType: "application/json; charset=utf-8",
  type: "POST",
  dataType: "json",
  timeout: 15000,
  crossDomain:true,
  cache: false,
  async:false,

  success:function(data)
  { 
     alert(data.Status);
  }
}); 

};

Time out Screen shot(checking in Eclipse)..

enter image description here

4

1 に答える 1

1

外部ドメインへのリクエストをホワイトリストに登録するにExternalHostsは、iPhone プロジェクトのPhoneGap.plistファイルのプロパティを に設定してみてください。*

次のコードを JS ファイルに追加して、webView で実行されたときに jQuery フレームワークでクロスドメイン リクエストが有効になるようにすることもできます。

$( document ).on( "mobileinit", function() {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
});

また、少なくとも以前のバージョンの jQuery では、jsonp タイムアウト エラーが無視されるという問題がありました (呼び出しで設定crossDomain:trueする$.ajaxと、jQuery モバイルで jsonp にフォールバックする可能性があると思います)。したがって、次のプラグインを使用してみることができます: jQuery-JSONP :

jQuery-JSONP はコンパクト (1.8kB 縮小) でありながら機能満載の、JSONP の jQuery の実装に代わるソリューションです。

[...]

jQuery-JSONP 機能:

  • タイムアウトメカニズム。

これにより、次の行に沿って呼び出しが何かに変わります(の$.jsonp代わりに関数を使用することに注意してください$.ajax

$.jsonp({
    "url": url,
    "data": "",
    "datatype": "json"
    "timeout": 15000,
    "success": function(data) {
        alert(data.Status);
    },
    "error": function(d,msg) {
        alert("Could not find user "+userId);
    }
});
于 2013-08-02T06:06:53.340 に答える