Problem sending an AJAX request with headers on Blackberry Webworks

I am developing a Blackberry web application and I am having problems with the AJAX request I make on the server. I learn HTML / Javascript / AJAX "on the fly", so I apologize for the beginning errors. Basically, formatted HTTP requests go to a server, which returns the JSON objects that I use in the application. I use AJAX for queries without any frameworks. Most requests do not have to be authenticated, and they are returned in order. However, to access part of the directory on the server, the username and password are encoded and sent as a header using XMLHTTPRequest. when I try to add a header, the request is sent, but I never get anything. The readyState property has a value of 1, but never goes beyond that. I know the server works fine because I did the same for the iPhone and it worked.

Here is the relevant code:

function grabFromServer(httpRequest){ httpConnection = new XMLHttpRequest(); var me = this; httpConnection.onreadystatechange=function(){ alert(httpConnection.readyState); if(httpConnection.readyState==4){ me.processResponseText(httpConnection.responseText); } }; httpConnection.open("GET", httpRequest,true); if(this.request == "company" || this.request == "property" || this.request == "individual"){ var authorized = this.checkCredentials(); if(!authorized){ //ask for username pword } //here, add credentials httpConnection.setRequestHeader("Authorization", "Basic : ODI5ZGV2bDokY19kdXN0Ym93bA=="); } httpConnection.send(); 

}

+4
source share
1 answer

Your code seems good. Have you added an entry to your config.xml file to allow access to your domain? You should see an entry for something like <access subdomains="false" uri="http://data.mycompany.com/"/> . To do any HTTPRequests on an external website from a WebWorks application, you need to add a whitelist entry, for example:

If you use the eclipse plugin, open the config.xml file, click on the "Permissions" tab at the bottom and click "Add Domain".

+1
source

Source: https://habr.com/ru/post/1347144/


All Articles