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
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom
Accepted Solution

Ajax Webservice calls Sometimes Failing randomly.

I have a problem with blackberry 6 & 7. My webservice calls just fails randomly for no reason. The calls work. A lot of the time they are successful. But sometimes it is almost like it just fails immediately. 

 

I added a timeout element and disabled websecurity but it is still failing randomly. Do you guys have any idea of what I can try to do and improve this ? it is really bad and I need help quite promptly... Below I include a few code snippets.

 

 

in config.xml

 

<rim:connection timeout="60000" />
 
  <feature id="blackberry.app">
    <param name="websecurity" value="disable" />
  </feature>


inmy javascript file...

 

function GetAssistanceProductsWebServiceHoezit() {
 
    showBusy("Retrieving Info...");
    $.ajax({
        async: false,
        beforeSend: function (request) {
            request.setRequestHeader("Device", reportingDeviceId);
        },
        complete: function () { hideBusy(); },
        type: 'GET',
        url: GetAssistanceProductsWsUrl() + '&SystemUserId=' + sessionStorage.userId,
        contentType: 'application/json',
        dataType: 'json',
        data&colon; '',
        success: function (resultMessage) {
            sessionStorage.wasSuccessful = resultMessage.WasSuccessful;
            if (resultMessage.WasSuccessful == true) {

                // do stuffs
                hideBusy();
            } else {
                var buttons = ["OK"];
                var ops = { title: resultMessage.Heading, size: blackberry.ui.dialog.SIZE_SMALL, position: blackberry.ui.dialog.CENTER };
                blackberry.ui.dialog.customAskAsync(resultMessage.Description, buttons, dialogCallBack, ops);
            }
        },
        error: function () {
            var buttons = ["OK"];
            var ops = { title: "Failed:", size: blackberry.ui.dialog.SIZE_SMALL, position: blackberry.ui.dialog.CENTER };
            blackberry.ui.dialog.customAskAsync(genError, buttons, dialogCallBack, ops);
        }
    });
    hideBusy();
}

 

 

 

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,523
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ajax Webservice calls Sometimes Failing randomly.

When it fails, what HTTP Response code and error message are being reported? Have you connected Web Inspector to take a look at the Network Request? These will help give us a better idea of what is happening; there are many reasons a request could fail / be rejected by a server. Without more detailed information on the error it's going to be difficult to say.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom

Re: Ajax Webservice calls Sometimes Failing randomly.

[ Edited ]

I tried setting up web inspector but I gave up after not getting it working. I never get the developer tools menu on the phone. Even after I turned developer tools on. All my webservices work 100%. The problem seems that I can now load say profile information and it works. then 2 min later I try to do so again and it fails like 5 times in short succession then works again... I have other apps written in webworks that works and doesn't have this same problem. Other apps might fail once in like 50 tries. It looks like the device is not even making a request before saying it failed.

Please use plain text.
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom

Re: Ajax Webservice calls Sometimes Failing randomly.

Can you maybe help me to get the web inspector set up ?

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,523
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ajax Webservice calls Sometimes Failing randomly.

[ Edited ]

On BlackBerry 7, if you're using just the native OS browser, you can enable Web Inspector as follows:

 

On a BlackBerry smartphone or on the BlackBerry Smartphone Simulator, open the BlackBerry Browser.
In the browser, open the browser menu and click Options.
In the Web Content portion of the screen, check Enable Developer Tools. Enabling the developer tools causes the Developer Tools menu item to be displayed in the browser menu.
Save the change and exit the Options screen.
Open the browser menu, and select Developer Tools > Enable Web Inspector. The browser displays a dialog box that indicates that the Web Inspector is now enabled, and provides the IP address and the port number (1337) required to connect from your desktop browser.

 

However if you are packaging a WebWorks Application, you will need to follow these steps:

https://developer.blackberry.com/bbos/html5/documentation/enabling_webinsp_microsite_1987478_11.html

 

Specifically, using the -d flag when building your application.

 

I also put together this sample that outputs the content to a div on the screen as opposed to the Web Inspector console. Would you be able to host this / test this index.html and see if you can reproduce the error with your own custom URL? I've highlighted the location to modify the URL in blue.

 

<!DOCTYPE html>
<html>
  <head>
    <title>jQuery AJAX</title>
  </head>
  <body>
    <div id="container" style="font-size: 10px;"></div>

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
      /*global window, document, console, alert, $ */
      var el;

      function log(value) {
        var div = document.createElement('div');
        if (typeof value === 'string') {
          div.innerHTML = value;
        } else {
          div.innerHTML = JSON.stringify(value);
        }
        el.appendChild(div);
      }

      window.addEventListener('load', function () {
        el = document.getElementById('container');

        $.ajax(
          'https://cors-test.appspot.com/test',
          {
            'async': false,

            'beforeSend': function beforeSend(jqXHR, settings) {
              log('&nbsp;');
              log('********************************');
              log('********** beforeSend **********');
              log('********************************');
              log('&nbsp;');
              log('jqXHR');
              log(jqXHR);
              log('settings');
              log(settings);
            },
            'success': function success(data, textStatus, jqXHR) {
              log('&nbsp;');
              log('*****************************');
              log('********** success **********');
              log('*****************************');
              log('&nbsp;');
              log('jqXHR');
              log(jqXHR);
              log('textStatus');
              log(textStatus);
              log('data');
              log(data);
            },
            'complete': function complete(jqXHR, textStatus) {
              log('&nbsp;');
              log('******************************');
              log('********** complete **********');
              log('******************************');
              log('&nbsp;');
              log('jqXHR');
              log(jqXHR);
              log('textStatus');
              log(textStatus);
            },
            'error': function error(jqXHR, textStatus, errorThrown) {
              log('&nbsp;');
              log('***************************');
              log('********** error **********');
              log('***************************');
              log('&nbsp;');
              log('jqXHR');
              log(jqXHR);
              log('textStatus');
              log(textStatus);
              log('errorThrown');
              log(errorThrown);
            },

            'contentType': 'application/json',
            'data': '',
            'dataType': 'json',
            'type': 'GET'
          }
        );
        log('&nbsp;');
        log('*****************************************');
        log('********** Sync AJAX returned. **********');
        log('*****************************************');
        log('&nbsp;');
      }, false);
    </script>
  </body>
</html>

 

If you are able to reproduce the error, could you please COPY/PASTE the output and share it here? If you need to replace any content (i.e. private URLs, etc.) please do so with @ symbols.

 

UPDATE

 

I've also noticed that in your sample, you are monitoring for errors, do any error messages appear that you could share?

 

Also, if you hit any issues at any of the steps, please let me know at which step.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom

Re: Ajax Webservice calls Sometimes Failing randomly.

Thank you for your detailed reply. I started playing around with the remote web inspector and got it working using safari. (chrome does not seem to work...).  On safari I don't seem to have a network tab to monitor http requests. But I let the phone log the error msg. My calls seems to work 100% in ripple but not on the phone.

 

I got the code you sent me working and did not get any of the failed ws calls I seem to get.

 

So when I logged the exception error of the failed ws call, I got this error. "NETWORK_ERR: XMLHttpRequest Exception 101"  

 

The error seems strange since I made a JSON request. After I googled a bit, I saw someone suggesting to use async : true.  I would prefer not to use this, but I am going to try this now and I'll let you know if this helps.

 

Thank you for all your trouble in trying to help me. I really appreciate it a lot. 

Please use plain text.
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom

Re: Ajax Webservice calls Sometimes Failing randomly.

Ok so I changed all my ws calls to Async: true. But this gives me some issues. The UI is not always blocked and when the user interacts with the page the ws call gets disrupted, so I cannot use async calls. this is a shame since my first ws call that I changed to async seemed to have imrpoved... Do you know what the exact meaning of XMLHttpWebRequest 101 is ?

 

Please use plain text.
Contributor
Marcel21405
Posts: 16
Registered: ‎08-01-2013
My Device: Bold 9900
My Carrier: Vodacom

Re: Ajax Webservice calls Sometimes Failing randomly.

Hi Again. So after making some changes and it looks like I fixed my problem.

 

I used to call the ws calls on pageshow. When I change this to pageinit. It looks like it is working without any problems. I just wanted to say thank you for all your trouble in helping me. If I still have problems, I will post here again. :smileyhappy:

Please use plain text.