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
Highlighted
Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer
Accepted Solution

xmlHttpRequest is returning no response in blackberry 10 webworks

Hi, 

 

I am using below link to send an http get request in blackberry webworks application. 

 

https://github.com/blackberry/WebWorks-Community-Samples/blob/master/kitchenSink/js/browser/xhr.js

 

Calling updateContent (http://www.google.com) on click of button.

 

I have whitelisted the url in config.xml.

Now getting response as blank and req.status as 0.

 

Please let me know what I am doing wrong.

 

 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: xmlHttpRequest is returning no response in blackberry 10 webworks

[ Edited ]

Based on some testing:

 

<!DOCTYPE html>
<html>
	<head>
	</head>
	<body>
		<script type="text/javascript">
			/*global window, document, console, alert, XMLHttpRequest */

			window.addEventListener('load', function () {
				var xhr;

				xhr = new XMLHttpRequest();
				xhr.open('GET', 'http://www.domain.com', true);
				xhr.onreadystatechange = function () {
					console.log(xhr.readyState);
					console.log(xhr.status);
				};
				xhr.onload = function () {
					console.log(xhr.status);
					console.log(xhr.response);
				};
				xhr.send();
			}, false);
		</script>
	</body>
</html>

 

Where I've substituted http://www.domain.com with various URLs, I am seeing a readyState 4, status 0 come up often when there is a security violation due to cross-domain requests. This is not something that can exactly be fixed on the client side if the server is denying that sort of access.

 

When I made the request to a domain on the same server that was hosting the above sample index.html, the request worked just fine.

 

You can test this further here:

http://www.test-cors.org

 

Note that a request to http://www.google.com results in an error, while a request to https://cors-test.appspot.com/test succeeds.

 

 

EDIT: What this amounts to then is that the destination server likely is not allowing Cross-Origin requests, and you simply won't be able to make the request to that URL.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.