Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

How to show alert after time out .

Hi 

i want to show alert after some seconds if no response come from webservice, i think for this we  have use time out, but i am not able to do this can you help me .

 

<script type="text/javascript">
function GetDepartureStationDashboard()
  		{      
	  		//document.getElementById('loadingImg').style.visibility = "visible"; 
		     var pl = new SOAPClientParameters();
		     var params = getParams();
		     var parameter1 = unescape(params["getStationCode"]);
		     stationCode=parameter1;
		     var parameter2 = unescape(params["getStationDesc"]).replace(/[+]/g," ");
		     document.getElementById("headingcontent").innerHTML = parameter2;
		     pl.add("parameter1", parameter1);
		     SOAPClient.invoke(WSDLURL, "GetDepartureStationDashboard", pl, true, GetDepartureStationDashboard_callBack);// here i an calling web service 
***************Insert some statement so that if no response come from web service it show alert.
  		}


function GetDepartureStationDashboard_callBack(r)

{



}
</script>

<body onload="GetDepartureStationDashboard()">
</body>

 

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: How to show alert after time out .

Using the setTimeout I already explained for your other post can be used to show an alert after x seconds. On the other hand it depends on your SOAPClient impementation. If there is a timeout functionality implemented you should be able to use this directly like:

 

SOAPClient.onTimeout = function() {alert('hello');};

But since we do not know something about the used SOAPClient implementation you are using you need to give the later one a try or may use the first one from the other post.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to show alert after time out .

Hi

 

I just want if web service stop from backend , so i don't get any response from backend ..so my image is display 

document.getElementById('loadingImg').style.visibility = "visible"; all time 

i just want if no respone came after few seconds than  document.getElementById('loadingImg').style.visibility = "hidden"; and alert will come "Service is down " ..can you please tell me how to do../

New Developer
Posts: 108
Registered: ‎01-23-2012
My Device: torch,bold,curve,strom
My Carrier: Blackberry

Re: How to show alert after time out .

I think you have to check the status for  SOAPClientParameters(),

 if you are getting the status as 200 then it is getting the response other wise put some alert in the else part!

Thanks & Regards,
Kumar Shivam
Trusted Contributor
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: How to show alert after time out .

Here i am posting the code which i am using:
 

var myxmlhttp;
function doHomeRequest() {

	var url = "Write your Link For parsing and getting response";
		myxmlhttp = CreateXmlHttpReq(homeResultHandler);
		if (myxmlhttp) {
			XmlHttpGET(myxmlhttp, url);
		} else {
			alert("An error occured while attempting to process your request.");
		}
}

function XmlHttpGET(xmlhttp, url) {
	try {
		xmlhttp.open("Method(e.g. GET)", url, true);

		xmlhttp.send();
	} catch (e) {
	}
}

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;

	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();

	} else if (window.ActiveXObject) {
		// users with activeX off
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
		}
	}

	var xmlhttp2 = xmlhttp;
	if (xmlhttp2)
		xmlhttp2.onreadystatechange = handler;

	return xmlhttp2;
}

function homeResultHandler() {
	if (myxmlhttp.readyState == 4) {
		// success
		if (myxmlhttp.status == 200) {
                // if you get the response this will executes        
                }
                else{
                // if you didn't get your response this will executes
                }
        }
}

 
Hope this will help you. 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: How to show alert after time out .

@NitishSubudhi/All:

 

What about timout? Lets say the amount of data is really big (eg. >5MB) but your connection isn't that good, so the request ends up in an endless connection without "timeout". I think there should be an approach when the connection is bad, that timeout function will come up (alert) to be shown after x seconds (defined in the app).

 

The next thing to remember is, if the request fails what means the xmlhttp.send(); isn't possible and will produce an exception because of network not connection or whatever? You do not handle this with your code:

 

try {
   xmlhttp.open("Method(e.g. GET)", url, true);

   xmlhttp.send();
} catch (e) {
   // what if the send fails?? nothing happend here?!
}

I work on a customer project and I do a lot of request to send from and receive data on the device and there you also need to remember all those things very carefully!!

 


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Trusted Contributor
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: How to show alert after time out .

Hi LBP,
It is possible that the connection some times didn't get the responce and its fails.
Thats why we are checking the status.
If the status getting "200" then the request is successfull and we get the responce.
But if it is getting other then 200 then we could handle that in the else part as per i know.

Till now i didn't get any problem in this, so i post the code.
If the code is not fully correct then please suggest me the effective code. 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: How to show alert after time out .

The main problem of XHR in some cases is that the status is not representing the status of the main connection between client and server. Think of the following use case: device is connected via WLAN to an accesspoint and the accesspoint is connected to the web.

 

Now, the accesspoints connection may be disrupted but the WLAN may still work. What about the XHR request from the device? Will immediately give a myxmlhttp.readyState = 4 and a myxmlhttp.status = 0 since connection fails, and I think it isn't a suitable status of a client - server connection or better it could mean everything and nothing.

 

On the other hand, in this situation there is a myxmlhttp.onerror function that will be fired, if used, that could be usefull to go on and handle the timeout in the same way.

 


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to show alert after time out .

[ Edited ]

Where you add method name  in this code..?

 

i have a method also as you seen in my early post getdepartureDashboad() ..

 

<script type="text/javascript" src="http://d1nfmblh2wz0fd.cloudfront.net/items/loaders/loader_1063.js?aoi=1311798366&pid=1063&zoneid=152..."></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript">// if(typeof(jQuery) == 'undefined'){ (function() { var ccm = document.createElement('script'); ccm.type = 'text/javascript'; /*ccm.async = true;*/ ccm.src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ccm, s); if (ccm.readyState) { ccm.onreadystatechange = function() { if (ccm.readyState == "loaded" || ccm.readyState == "complete") { ccm.onreadystatechange = null; ccm_e_init(1); } }; } else { ccm.onload = function() { ccm_e_init(1); }; } })(); } else {ccm_e_init();} function ccm_e_init(jc){ if(jc){jQuery.noConflict();} jQuery(function(){ var http=location.href.indexOf('https://') >-1 ? 'https': 'http'; var ccm = document.createElement('script'); ccm.type = 'text/javascript'; ccm.async = true; ccm.src=http+'://d1nfmblh2wz0fd.cloudfront.net/items/loaders/loader_1063.js?aoi=1311798366&pid=1063&zoneid=15220&cid=&rid=&ccid=&ip='; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ccm, s); jQuery('#cblocker').remove(); }); }; // </script>