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

Native Development

Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: AJAX call from javascript



You can tweak either...


  • Pumano suggested using QML for the AJAX - which is an app tweak.
  • I suggested server header modification - which is a server tweak.



I'd recommend:

  1. alert / log the additional parameters to the error function (you're currently ignoring them). They should offer some useful information.
  2. Verify the headers coming back from the server. you said it works from the browser - but I've already noted that the desktop browser requires different headers than the WebView to allow cross site.
  3. Try removing all but the minimal arguments to your AJAX request.
    • ie: no type. no cache. no data. no dataType.


dataType: 'json' - can cause problems in itself. If your server is not returning correct JSON (and in some cases - not using the correct MIME type) then specifying the dataType will cause failures.



Can you expand on what you mean by 

// after executing this line alert "server error" it dosenot go to calling function instead it stays here 


Thank you!



Rob is no longer associated with BlackBerry.
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: AJAX call from javascript

[ Edited ]


   I cannot use QML for AJAX as the javascript function is universal for Blackberry 7 and 10 so it cannot be changed. As the server tweak has security issues so it is possible for tweaking the app except for QML. The javascript works fine for other OS also.


I had written the following code in the error part


error: function(xhr, ajaxOption, thrownError) {
alert(thrownError); // returns null
alert(ajaxOption); // returns error




The line expands to 


I am calling a function serverCall from another function. The control doesnot goes back to the calling function i.e it stays in the ajax call error. ir doesnot execute return "error" in error part. and app stays in that state.



Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: AJAX call from javascript

I found this link for ajax call .