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

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 21
Registered: ‎01-17-2012
My Device: BlackBerry 9550
My Carrier: ???
Accepted Solution

Browserfield XMLHttpRequest not valid

I'm trying to launch an ajax request from javascript inside of a BrowserField.

Here is a demo application, it's just an html element which tries to make an ajax request on click.

 

public MyScreen() {
		// Set the displayed title of the screen
		setTitle("MyTitle");

		BrowserFieldConfig _myBrowserFieldConfig = new BrowserFieldConfig();

		_myBrowserFieldConfig.setProperty(
				BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
		_myBrowserFieldConfig.setProperty(BrowserFieldConfig.ALLOW_CS_XHR,
				Boolean.TRUE);
		BrowserField browser = new BrowserField(_myBrowserFieldConfig);
		browser.displayContent(
				"<!DOCTYPE html><html><head>"
						+ "<script>function loadXMLDoc(){"
							+ "alert('t'); "
							+ "var xmlhttp;"
							+ "if (window.XMLHttpRequest) "
							+"{ "
								+ "xmlhttp = new XMLHttpRequest();  "
							+ "} "
							+ "else { "
								+ "xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");  "
							+ "}"
							+ " xmlhttp.onreadystatechange=function()  "
							+"{ "
								+ " if (xmlhttp.readyState==4 && xmlhttp.status==200) "
								+ "{"
//									+ " document.getElementById(\"myDiv\").innerHTML=xmlhttp.responseText;"
								+ "}"
								+"alert('State:'+xmlhttp.readyState+ 'status'+ xmlhttp.status)"
							+ "} "
							+ "xmlhttp.open(\"GET\",\"http://www.w3schools.com/ajax/demo_get.asp\",true);"
							+ "xmlhttp.send(); "
							+ "}"
						+ "</script>"
						+ "</head><body><h2>AJAX</h2><a onclick=\"javascript&colon;loadXMLDoc();\">Request data</a><div id=\"myDiv\"></div></body></html>",
				"http://www.w3schools.com");
		add(browser);
	}

 

The problem is that even the first alert is not working, so there should be a javascript syntax error, but well, everything looks good to me. I tried this code from Firefox on my computer and the alerts are shown (I know cross-domain isn't always possible). So, what is the error in my script ?

I have tested this on the simulator with BB 5.0.0 and 7.0.0.

New Contributor
Posts: 4
Registered: ‎01-27-2012
My Device: Developer
My Carrier: Orange

Re: Browserfield XMLHttpRequest not valid

I have the same problem.

Have you find a solution ?

Contributor
Posts: 21
Registered: ‎01-17-2012
My Device: BlackBerry 9550
My Carrier: ???

Re: Browserfield XMLHttpRequest not valid

[ Edited ]

I find the solution.

What is wrong is to use an absolute url to open the XMLHttpRequest. It needs to use a relativie url (demo_get.asp) and the browserfield needs to have the baseurl set correctly (http://www.w3schools.com/ajax/).

That's very inconvenient.

New Contributor
Posts: 4
Registered: ‎01-27-2012
My Device: Developer
My Carrier: Orange

Re: Browserfield XMLHttpRequest not valid

Ty bro.

The other f****g developpers just says "I solve the problem".

You, you give the solution, thanks.