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
New Contributor
guligo
Posts: 9
Registered: ‎03-23-2010
My Device: -

AJAX Problem on BB Widget

[ Edited ]

Hi!

 

We have developed simple BlackBerry Widget (on Widget SDK Beta 3) that uses web-services. Calls to web-services are done with AJAX technique (XMLHttpRequest). During the development of application we came accross couple of issues and maybe someone could help us to clarify things :smileyhappy:

 

1) We weren't able to send requests with "Authentication" header. Header is added to request in code, but it seems not to be included when request is sent. Is it related to https://www.blackberry.com/jira/browse/WEBAPI-21 issue?

 

2) XMLHttpRequest object doesn't seem to work well with large data. As we have observed - if XMLHttpRequest object receives large XML in response, it stops processing after first portion of data. Here is sample code snippet:

 

var request = new XMLHttpRequest();
request.open("POST", "http://some-url", true);
request.onreadystatechange = function() {
alert(this.readyState + ": " + this.responseText.length);
};
/* assume that response to this request is 6806 bytes long */
request.send(some_xml);

 

Running this code in FireFox will produce following alerts:

1: 0

2: 0

3: 2820

3: 5640

3: 6806

4: 6806

 

Running this code as BlackBerry Widget results in:

1: 0

2: 0

3: 2048

 

Obviously for BlackBerry Widget XMLHttpRequest stops processing too fast. Did anyone had such problem? And what could be the reason for such behavior?

 

P.S.

When will be next version of Widget SDK available?

 

Thanks in advance!

 

Please use plain text.
Retired
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: AJAX Problem on BB Widget

Hi Guligo,

 

Thanks for your post.  Let me answer your questions:

 

1) Yes, likely the reason why you are not seeing the Authentication header is due to this outstanding defect.  I will update that issue tracker item when information becomes available about when this fix has been made.  In the meantime, you can vote / follow it to stay up to date on it's progress.

 

2) I believe you may be missing some headers in your POST AJAX code.  Ensure that the 'Content-type" and 'Content-length" headers are being sent.  Try this:

 

 

var request = new XMLHttpRequest();
request.open("POST", "http://some-url", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function() {
   alert(this.readyState + ": " + this.responseText.length);
};
/* assume that response to this request is 6806 bytes long */
request.send(some_xml);

 

If you haven't done so already, I'd recommend checking out the XmlHttpRequest view window that is available to you through the BlackBerry Web Plug-in.  This window lets you see the request and response data that is sent as part of XHR communication.

 

 

Cheers,

Adam

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: AJAX Problem on BB Widget

Also, there is a maximum JavaScript string length that is 512KB in size.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
guligo
Posts: 9
Registered: ‎03-23-2010
My Device: -

Re: AJAX Problem on BB Widget

[ Edited ]

Thanks for your responses!

As you proposed, I have tried to add 'Content-type' and 'Content-length' headers to request, but that gave no result. String size of XML response is only ~7000 bytes long, so that's not the problem.

Also have checked out XmlHttpRequest View in Eclipse. Under XmlHttp Requests tab there are all requests that application has sent, but under XmlHttp Response tab not all the responses are shown (the ones with large data aren't). However they definetely are sent back, because I have done request/response tracing on TCP level.

Please use plain text.
Developer
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330

Re: AJAX Problem on BB Widget

[ Edited ]

Hi guligo,

 

Having a similar problem. You may want to checkout and/or keep an eye on these threads in case the issue is related:

 

http://supportforums.blackberry.com/t5/Web-Development/Random-null-response-in-Ajax-request/td-p/462...

 

http://supportforums.blackberry.com/t5/Web-Development/Retrieving-HTML-data-from-an-external-cross-d...

 

What technology stack are you utilizing on your server side?

 

Thanks

 

Please use plain text.
New Contributor
guligo
Posts: 9
Registered: ‎03-23-2010
My Device: -

Re: AJAX Problem on BB Widget

Hi nrizz,

Tnx for the links! Will definetly subscribe for those threads...

First we used Google App Engine for server-side. Web-application itself is written in Java and I think Google Apps uses Jetty as web-server. We use no JSPs or other dynamic web-pages and in general all responses are generated from Java code.

Recently we re-wrote server-side so that it could be deployed on SAP NetWeaver.

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: AJAX Problem on BB Widget

[ Edited ]

Hi Everyone,

 

We have been trying to get to the bottom of this.  This is what we have tried so far:

 


1) Created a server side web page that randomly returns different lengths of data on each request
2) Created a client that uses AJAX to call this URL and then check the resultant string to ensure that it AJAX result is not null
3) Run this test in a loop for a thousand or so iterations

These tests were all done on physical devices.  We also then ran them on simulators that were bundled in our latest build that is just about to be released.  These simulator tests were run on Windows XP.
  
In these tests we were not able to receive a single null response and all tests succeeded.  This is actually how we found the 512KB limit for JavaScript Strings and adjusted our tests so that they would not return more than 512KB of data.
  
We are now going to run the same test using the Widget Packager and Simulators from the Beta 3 SDK.
  
I'm leaning towards some kind of environmental difference between our test environment and your development environments.
  
Can you please post up the following information:
- Windows Version and if it is 32/64 bit
- Version of the BlackBerry Widget SDK that you are using
- Version of the BlackBerry OS that is being used on the simulators you are testing with
  
We'll continue to try and track down the root cause to this issue.
 
Thank you for both your patience and assistance 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: AJAX Problem on BB Widget

Another thought we had from one of our groups was that there may be some special characters in the returned data that is causing some kind of issue.

 

As you are running your tests, can you see if there is a relationship between some kind of special character in the return data and the null response?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
guligo
Posts: 9
Registered: ‎03-23-2010
My Device: -

Re: AJAX Problem on BB Widget

Hi tneil,

Here is information about my dev-environment:
- Windows XP Professional SP2 (32bit version);
- BlackBerry Widget SDK 1.0 Beta 3;
- OS 5.0 (9000, 9500).

So far I haven't noticed any relationship between special characters and return data (have thought about it already before). However will try to check again, maybe will find something suspicious...

Thanks!

Please use plain text.
Developer
nrizz
Posts: 26
Registered: ‎01-13-2010
My Device: 8330

Re: AJAX Problem on BB Widget

[ Edited ]

Hi Tim,

 

Heres the info as requested:

 

Windows Vista Business 32-bit Service Pack 2

BlackBerry Widget SDK 1.0 Beta 3;

OS of the 9500 simulator is 5.0.0.451

OS of the 9700 simulator is 5.0.0.442

OS of the 9550 simulator is 5.0.0.334

OS of the 9500 simulator is 5.0.0.252

 

Have you guys tried a non-.net server? I noticed that guligo and I are both using Java to serve up our data. Did you receive my email to devsupport? And also, was that you guys pinging my server like crazy :smileytongue:

 

Thanks!

 

 

Please use plain text.