XMLHttpRequest in Nokia Browser
Hi..!!
I am having problems trying to get a XMLHttpResponse from a page... I had a code that works perfectly at Ovi Browser, but then comes the latest actualization "Nokia Browser" and now it doesn't works like before... :(
I'm gonna write my function here:
function getjson(){
var xhr;
var url = 'http://feed.finsat.com.mx/movilesV2/feedindicadores.asp';
var pincel = '';
//call the right constructor for the browser being used
if (window.ActiveXObject) {
//xhr = new ActiveXObject("Microsoft.XMLHTTP");
try {
xhr = new ActiveXObject("MSXML2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
else
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
pincel += 'AJAX request not supported';
}
xhr.open("GET", url, false);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status == 200) {
if (xhr.responseText != null) {
pincel += xhr.responseText;
}
else {
pincel+='Failed to receive RSS file from the server - file not found.';
return false;
}
}
else {
pincel += "Error code " + xhr.status + " received: " + xhr.statusText;
}
}
}
xhr.send(null);
document.getElementById('Noticias').innerHTML=pincel;
}
I am just trying to print the textResponse on a Div, and it works over the simulator, but it doesn't works at the nokia Browser in Device, and also It worked before the actualization on Ovi Browser...
Does anybody have a solution for this problem...??
Thanks in advance...
Chelix
Re: XMLHttpRequest in Nokia Browser
Hi,
Your code sort of works. It will get the response back correctly but the text just won't be displayed on the device screen.
What you could do is to make GET request asynchronous xhr.open("GET", url, true); and modify the rest of the code to work in asynchronous way.
In addition you could get rid of the IE related xhr stuff at the beginning as it is not needed.
Br,
Ilkka
Re: XMLHttpRequest in Nokia Browser
[QUOTE=isalento;852235]Hi,
Your code sort of works. It will get the response back correctly but the text just won't be displayed on the device screen.
What you could do is to make GET request asynchronous xhr.open("GET", url, true); and modify the rest of the code to work in asynchronous way.
In addition you could get rid of the IE related xhr stuff at the beginning as it is not needed.
Br,
Ilkka[/QUOTE]
Hi Ilkka...!!!
Thanks for your answer... My code is actually working on emulator... Besides I've written a simplier function.. Just to get the responseText.. Here the code:
[CODE]function getJSON(){
var xhr;
xhr = new XMLHttpRequest();
xhr.open("GET", 'http://feed.finsat.com.mx/movilesV2/feedindicadores.asp', true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status == 200) {
document.getElementById('Noticias').innerHTML= xhr.responseText;
}
else {
document.getElementById('Noticias').innerHTML= "Error code " + xhr.status;
}
}
}
xhr.send(null);
}[/CODE]
It still worknig on emulator, and shows me the JSON that I want... But running the same application at Nokia Browser by url shortener it returns me an Error code 0... :(
Perhaps is a bug on Nokia Browser... It worked before the last actualization... :S
Re: XMLHttpRequest in Nokia Browser
Hi,
That looks good. I don't know why the device won't render the plain JSON response to the screen anymore. Anyhow the next step is to refine the data to be displayed.
In this code plain eval is used, but you might want to use some dedicated parsing script to make Web App more robust & secure.
[code]
...
if (xhr.status == 200) {
parse(xhr.responseText);
}
...
function parse(responseText){
var obj = eval('(' + responseText + ')');
var text = "";
for (var i = 0; i < obj.ResultSet.Result.length; i++) {
var result = obj.ResultSet.Result[i];
text += result.categoria +"<br>";
}
document.getElementById("noticias").innerHTML = text;
}
[/code]
-Ilkka
Re: XMLHttpRequest in Nokia Browser
Thanks Ilkka... I already have a parseJSON function, but It won't work if I can't get the responseText of the XMLHttpRequest :(
I really need some help here...!!! :S
Re: XMLHttpRequest in Nokia Browser
Have you checked [url]http://www.developer.nokia.com/info/sw.nokia.com/id/65924e82-57f4-475b-990d-7d1b2c058487/Series_40_Web_App_Qype.html[/url] ?
It should help!
Re: XMLHttpRequest in Nokia Browser
[QUOTE=lorion84;852870]Have you checked [url]http://www.developer.nokia.com/info/sw.nokia.com/id/65924e82-57f4-475b-990d-7d1b2c058487/Series_40_Web_App_Qype.html[/url] ?
It should help![/QUOTE]
Thanks for your answer lorion84... I tried to make the example.. In emulator it works.. I can see the list of countries.. But when I deploy and try to see the app at the Nokia Browser, happens the same problem, I can't see the list, I guess that the problem is at the XMLHtttprequest, it doesn't send the JSON response... :(
I have done the RSSReader example too, but neither it works... The XMLHttpRequest doesn't send response... :(
I have updated the firmware version of my Nokia X-3 02 Now I have V 06.00, and still doesn't works...!!!
Does anybody made works a simple example of this...??? I don't know if is a code mistake or a bug of Nokia Browser... Please Help... :(
Re: XMLHttpRequest in Nokia Browser
Am I the only one who is experiencing this kind of problem...??? :(
Re: XMLHttpRequest in Nokia Browser
Hi,
Well that sounds really strange.
What Browser version do you have installed at the moment? (Menu - > Tools -> About) and have you tested to reinstall the browser?
-Ilkka
Re: XMLHttpRequest in Nokia Browser
[QUOTE=isalento;853698]Hi,
Well that sounds really strange.
What Browser version do you have installed at the moment? (Menu - > Tools -> About) and have you tested to reinstall the browser?
-Ilkka[/QUOTE]
Hi Isalento..!!
The browser version that I am using is 1.0.3.23.12, and yes, I have reinstalled the browser about 3 times... Do you have any idea of what is happening..?? Thanks in advance...
Regards..
Chelix
Re: XMLHttpRequest in Nokia Browser
Hi Chelix,
I'm terribly sorry I forgot to get back to you. The issue you experienced was most likely due to use of a Beta version of Ovi Browser. Current version is Nokia browser is 1.5.0.34.15 and that should be used in development.
[url]http://download.browser.ovi.com/[/url]
Br,
Ilkka