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
Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330

Webworks-Ajax working in Firefox, not so much in Simulator

Hello,

My webworks works fine if i browse with firefox, However if I use the simulator my other buttons work just not the ajax ones.

I went into the config file and added my domain under permissions (http://ishopstark.com/mobileapp.php?category=2) and I added a header to my phgp page.

It does nothing when the button is clicked, but the other buttons work fine and this one works in firefox sooo..

Heres the code:

 

function Button3_onclick() {
xmlhttp=new XMLHttpRequest();
 
 
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
  //Change getuser.php to http://www.wateva.com/getstuff.php
  xmlhttp.open("GET","http://ishopstark.com/mobileapp.php?category=2",true);

  xmlhttp.send();
}

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Webworks-Ajax working in Firefox, not so much in Simulator

Have you tried whitelisting just the origin/domain itself

 

 

<access uri="http://ishopstark.com/mobileapp.php" subdomains="true" />

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 71
Registered: ‎02-04-2011
My Device: Blackberry Bold & Pearl

Re: Webworks-Ajax working in Firefox, not so much in Simulator

I would also suggest developing in Chrome as its built on the same WebKit tech as the BBOS6 and Playbook browsers.

Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330

Re: Webworks-Ajax working in Firefox, not so much in Simulator

Thanks for the Chrome tip.

 

Sorry it took so long getting back.  I tried just whitelisting the parent url allowing sub-domains and still nothing.

I also left the app and tried the simulators web browser and it works fine.

 

Im really at a loss here and I appreciate any and all help you fine folks here can give.

I have been going over the notes and videos here and still I cant seem to find whats wrong

 

Help :smileysad:

Contributor
Posts: 31
Registered: ‎12-05-2011
My Device: No

Re: Webworks-Ajax working in Firefox, not so much in Simulator

Yes,

 

I am getting same issue when I use xmlhttprequest. :smileysad:

 

Help will be appreciated

.

 

Developer
Posts: 268
Registered: ‎08-19-2009
My Device: Bold 9700

Re: Webworks-Ajax working in Firefox, not so much in Simulator

[ Edited ]

Hey all,

 

Cross-domain XHR requests are a real can of worms. Chrome seems to be more picky about it than FireFox, so I suggest using Chrome for all your XHR testing (the Inspector is your best friend). Both Chrome and BB use variations of WebKit so you can "generally" rely on Chrome for most testing.

 

Your server needs to return the following header :

 

Access-Control-Allow-Origin: *

 

This can be done in your PHP script: header("Access-Control-Allow-Origin: *");

 

Be aware setting this to the wildcard "*" is a bit insecure, but since I don't think you can set the header to a domain that accurately reflects the BB app, it might be the only option.

 

In your xhr.open() call, add the parameter "true" as the final parameter to indicate it is a cross-domain request.

 

E.g.,:

xhr.open("GET", "http://myFarAwayServer.com/test.php", true);

 

Cross domain XHR requests are a royal pain in the... If you Google them you will find hundreds of blog posts about it, mostly people complaining in the comments, etc. There dozens of solutions and they mostly feel like hacks and not all of them will work for a given situation. Fortunately there is light at the end of the tunnel with XHR 2, we just need to wait for browsers to catch up. So for now, we're stuck tinkering with an XHR house of cards.

 

For WebWorks stuff, I've found that if I can get the requests to work in Chrome then they'll work in my app. 

Contributor
Posts: 31
Registered: ‎12-05-2011
My Device: No

Re: Webworks-Ajax working in Firefox, not so much in Simulator

I installed  MDS and run. Problem resolved at my end :smileyhappy: