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
beben06
Posts: 8
Registered: ‎03-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: Orange

Ajax, JSON, crossDomain, CORS Options on BB10

[ Edited ]

Hello !

I converted and deploy my android application with the eclipse plugin to the extension .BAR for a smartphone BB10.

It's a hybrid application, which contains an in-app-broswer with an application html+css+js(jquery) and it's working on android, iphone, and platform bb before bb10 .

 

I do an AJAX CROSSDOMAIN request with jQuery like this:

 

$.ajax({
             type: "POST",
             url: "http://***************************.json",
             datatype: "json",
             crossDomain: "true",
             contentType: "application/json",
             data:'{"technicalNumber":"********","password":"****"}',
             scriptCharset: "utf-8",
             success : function(data) {
                    // do stuff
             },error: function(object, status, error){
                   // do other stuff
                   alert(error);
             }
}) ;

 

This POST call on a different domain, is subject to CORS concept, a preflight OPTIONS request is sent first.
The answer to this query returns an xml OPTIONS (with no value), which is interpreted and creates a type error at parseError JQuery.
 
On all other mobile platforms, the preflight request (OPTIONS) is not interpreted.
Are you aware of this error?

 

Thks in advance,

Ben

Please use plain text.
Contributor
alberry
Posts: 23
Registered: ‎02-22-2010
My Device: Z10

Re: Ajax, JSON, crossDomain, CORS Options on BB10

Do you have the following line on your config.xml file?

 

<access subdomains="true" uri="*"/>

 <feature id="blackberry.app" required="true" version="1.0.0.0">
        <param name="websecurity" value="disable" />
    </feature>

 OR Specify each domain individually (recommended):

 

<access subdomains="true" uri="www.mydowmain.com"/>

 

 

Please use plain text.
New Contributor
beben06
Posts: 8
Registered: ‎03-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: Orange

Re: Ajax, JSON, crossDomain, CORS Options on BB10

[ Edited ]

thks alberry;

 

It's a porting of an application ANDROID(.apk) to a BLACKBERRY 10(.bar) so i don't have access to the file config.xml (Or i don't know how access it?) However, in the manifest android there is permission to acces internet:

<uses-permission android:name="android.permission.INTERNET"/>

I configured my server to accept crossdomain requests:

# Allow origin for All / please uncomment the following lines :	
  Header set Access-Control-Allow-Origin "*"
  Header set Access-Control-Allow-Methods "POST,GET,DELETE,PUT,OPTIONS"
  Header set Access-Control-Allow-Headers "origin, method, content-type"

 

And if i use an ajax request GET on the domain it's working.

With post options i get an preflight request in xml...

On all others mobile platforms, the preflight request (OPTIONS) is not interpreted.

My ask is how to not interpret the preflight in ajax on BB10?

 

 

Please use plain text.
Contributor
alberry
Posts: 23
Registered: ‎02-22-2010
My Device: Z10

Re: Ajax, JSON, crossDomain, CORS Options on BB10

I suggest you repost your question in the Android Runtime forum. Here, people are more geared toward the WebWorks interface. 

Please use plain text.
New Contributor
beben06
Posts: 8
Registered: ‎03-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: Orange

Re: Ajax, JSON, crossDomain, CORS Options on BB10

Ok i will do :smileywink:

 

Just in case, have you ever done ajax post method in an app (containning the webbroswer and the files executing ajax) on a smartphone BB10?

Please use plain text.
Contributor
alberry
Posts: 23
Registered: ‎02-22-2010
My Device: Z10

Re: Ajax, JSON, crossDomain, CORS Options on BB10

Personally no. But it is feasible and should be documented with Cascade. Some cascade apps like Crackberry use in-app integrated browser. 

 

 

Please use plain text.
New Contributor
beben06
Posts: 8
Registered: ‎03-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: Orange

Re: Ajax, JSON, crossDomain, CORS Options on BB10

More information about the error:

Please use plain text.