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
Visitor
Posts: 1
Registered: ‎04-07-2011
My Device: Developer
My Carrier: Developer

Problem sending AJAX request with headers on Blackberry Webworks

[ Edited ]

 

I am developing a Blackberry webworks application and I am having trouble with an AJAX request that I am making to a server. I am learning HTML/Javascript/AJAX on the fly, so excuse any beginner mistakes. Basically, formatted HTTP requests are made to the server, which returns JSON objects that I use in the application. I am using AJAX to make the requests without any kind of framework. Most requests do not have to be authenticated, and those are returning just fine. However, to access a directory part of the server, a username and password are encoded and sent as a header with the XMLHTTPRequest. when I try and add the header, the request is sent, but I never get anything back. The readyState property is set to 1, but never goes beyond that. I know the server works fine, because I did the same thing for 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
			alert("bitch, whats the secret??");
		}
		//here, add credentials
		httpConnection.setRequestHeader("Authorization", "Basic : ODI5ZGV2bDokY19kdXN0Ym93bA==");
		alert("lets hope this works");
	}
	httpConnection.send();
}

 

I am developing a Blackberry webworks application and I am having trouble with an AJAX request that I am making to a server. I am learning HTML/Javascript/AJAX on the fly, so excuse any beginner mistakes. Basically, formatted HTTP requests are made to the server, which returns JSON objects that I use in the application. I am using AJAX to make the requests without any kind of framework. Most requests do not have to be authenticated, and those are returning just fine. However, to access a directory part of the server, a username and password are encoded and sent as a header with the XMLHTTPRequest. when I try and add the header, the request is sent, but I never get anything back. The readyState property is set to 1, but never goes beyond that. I know the server works fine, because I did the same thing for iPhone, and it worked.

 

Here is the relevant code