Reputation: 1531
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)..
Upvotes: 2
Views: 5738
Reputation: 6517
Try setting the ExternalHosts
property of your iPhone project's PhoneGap.plist
file to *
to whitelist requests to external domains.
You can also try adding the following code to your JS file to guarantee that cross-domain requests are enabled for the jQuery framework when it's executed in the webView.
$( document ).on( "mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
Also, at least in earlier versions of jQuery there were issues with jsonp timeout errors being ignored (and I think setting crossDomain:true
in your $.ajax
call can cause fallback to jsonp in jQuery mobile). So you could try using the following plugin: jQuery-JSONP:
jQuery-JSONP is a compact (1.8kB minified), yet feature-packed, alternative solution to jQuery's implementation of JSONP.
[...]
jQuery-JSONP features:
- a timeout mechanism.
Which would turn your call into something along the lines of the following (note the use of the $.jsonp
function instead of $.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);
}
});
Upvotes: 1