02-02-2011 06:09 PM
OK, you are going to want to kick my head, and I'll give you the reason ![]()
Debuging, I found out that responseText brought something like http://localhost... has no permissions ..." (or something like that).
So I realized in that moment that I hadn't include the port ![]()
So, when I included the domain http://localhost:9198 in my config.xml everything worked fine.
Thanks a lot.
I'll keep working in this so don't expect me to let you rest ![]()
Regards,
Paco
02-03-2011 06:24 AM
Hi, does this work in getting data from an MS SQL Database?
As the widget I am developing for my project for my foundation degree needs to access the data held ther and I am finding it difficult to find out how to get the data into my widget. (I am a newbie to blackberry development)
Many Thanks
Darren
02-03-2011 09:00 AM
Hi Darren,
This approach would work for remotely accessing a server side MS SQL Database that you wrap a web service layer around.
You cannot package a database file locally inside your WebWorks application. For local data you need to dynamically create a SQLite database and populate it through JavaScript
02-03-2011 12:05 PM
Hello,
As Tim told you, I would recommend building a web service layer to access SQL Server and then your webworks app consuming this services.
Good luck.
Best regards,
03-05-2011 04:24 AM
Easy way for Serialize to JSON from .NET Server:
System.Web.Script.Serialization.JavaScriptSerializer
toJson = new System.Web.Script.Serialization.JavaScriptSerializer();
return toJson.Serialize(this);
http://msdn.microsoft.com/en-us/library/bb292287.a
05-25-2011 03:38 PM
Hi,
I was never able to make your code work ( don't know why but, in my case, xmlHttp.readyState always return 1 ).
So I search a other way for accessing my web service and I found this code looking very similar to your's.
It work pretty well on remote/local web service and on OS5 (9800 Simulator) and Tablet OS (Playbook Simulator)
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<
html><head><metaname="viewport"id="viewport"content="initial-scale=1.0,user-scalable=no"/><scripttype="text/javascript"src="json_sans_eval.js"></script><scripttype="text/javascript">
function
doClick()
{
ajaxRequest();
}
function
ajaxRequest()
{
var ajaxrequest = new XMLHttpRequest( );
ajaxrequest.onreadystatechange =
function( )
{
if( ajaxrequest.readyState == 4 && ajaxrequest.status == 200 ) handleContent (ajaxrequest.responseText);
}
ajaxrequest.open(
'GET', 'http://your service address, true);
ajaxrequest.send( );
}
functionhandleContent(content) {
content.replace(/</g,
"<").replace(/>/g,">");
document.getElementById(
'div_result').innerHTML = content;
}
</script></head><body><buttononclick="doClick()">Get Async Response </button><divid="div_result"></div></body>
</
html>
06-09-2011 03:46 AM
FYI we have another article which explores the subject of WebWorks development and web services:
Full source included.
06-09-2011 09:25 AM
Hi,
This is a very usefull example but can you please provide example with Microsoft base web service.
And by the way can you provide example without JSon output because I already have my web service
and I don't want to recode it (and all other caller) just to fit with your example.![]()
And before leaving you when I test this function ( 9800 OS6 simulator) ...I don't know why but the
alert('2') raise before alert('1')...and in some case the row was inserted and in other
they don't without raising a error in a try catch. And for some reason I don't find explanation for
the same row have several alert('2') for one alert('1')...it look like the while loop work in reverse
mode...![]()
This is my parser...have fun:
function ParsePageFromXMLtoData(contentXML){
var iposDebut;
var iposFin;
var iposDebutBloc;
var iposFinBloc;
var content;
var contentBloc;
var PageID;
var PageTitre;
var PageMotCle;
var PageCouleurFond;
var PageDerniereModif;
var i;
var bInserted;
i=1;
contentXML.replace(/</g,"<").replace(/>/g,">
content=contentXML;
while (contentXML.indexOf("</PAGE>") > 0){
bInserted=false;
content=contentXML;
iposDebut = content.indexOf("<PAGE>");
iposFin = content.indexOf("</PAGE>");
content = Mid(content,iposDebut + 12,iposFin-iposDebut + 1);
iposDebutBloc=content.indexOf("<BLOCS>");
iposFinBloc=content.indexOf("</BLOCS>");
contentBloc= Mid(content,iposDebutBloc + 13,iposFinBloc-iposDebutBloc + 1);
contentXML = Mid(contentXML,iposFin-iposDebut + 13, contentXML.length - iposFin )
//ID
iposDebut = content.indexOf("<ID>");
iposFin = content.indexOf("</ID>");
PageID = Mid(content,iposDebut + 10,iposFin-10);
content = Mid(content,iposFin + 11 ,content.length-iposFin + 11);
//TITRE
iposDebut = content.indexOf("<TITRE>");
iposFin = content.indexOf("</TITRE>");
PageTitre = Mid(content,iposDebut + 13,iposFin-13);
content = Mid(content,iposFin + 14 ,content.length-iposFin + 14);
//MOTCLE
iposDebut = content.indexOf("<MOTCLE>");
iposFin = content.indexOf("</MOTCLE>");
PageMotCle = Mid(content,iposDebut + 14,iposFin-14);
content = Mid(content,iposFin + 15 ,content.length-iposFin + 15);
//COULEURFOND
iposDebut = content.indexOf("<COULEURFOND>");
iposFin = content.indexOf("</COULEURFOND>");
PageCouleurFond = Mid(content,iposDebut + 19,iposFin-19);
content = Mid(content,iposFin + 20 ,content.length-iposFin + 20);
//DERNIEREMODIF
iposDebut = content.indexOf("<DERNIEREMODIF>");
iposFin = content.indexOf("</DERNIEREMODIF>");
PageDerniereModif = Mid(content,iposDebut + 21,iposFin-21);
content = Mid(content,iposFin + 22 ,content.length-iposFin + 22);
Alert('1');
if (db) {
db.transaction(function (tx) {
tx.executeSql("SELECT * FROM t_page WHERE PageID = ?", [PageID], function (ax, results) {
if (results.rows.length>0){ bInserted=true;}
if (bInserted=true)
{
Alert('2');
uppage(PageID,PageTitre,PageMotCle,PageCouleurFond,PageD
}
else
{
if (bInserted==false){
Alert('2');
tx.executeSql('INSERT INTO t_page(PageID,PageTitre,PageMotCle,PageCouleurFond
[PageID,PageTitre, PageMotCle, PageCouleurFond, PageDerniereModif]);
bInserted=true;
}
}
});
});
}
i=i+1
ParseBlocFromXMLtoData(contentBloc)
}
}
08-31-2011 04:05 PM
Hi I am trying to get this working. I am running Blackberry Webworks Portal 2.1.1.3.8
Windows 7
Java 1.6
Simulator 9550
Phonegap 1.0
MDS that comes with BBWP (I needed to add a proxy port)
I can get to the internet via browswer. I added some things so I can see what is going on. It works when I run it directly in Firefox.
My phone gap app javascript:
var xmlHttp = new XMLHttpRequest();
function init2() {
var url = "http://ws.geonames.org/postalCodeSearchJSON?postal
xmlHttp.open('GET', url, true);
xmlHttp.onreadystatechange = callbackFunction;
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
document.getElementById('results').innerHTML = "Requesting...";
xmlHttp.send(null);
}
function callbackFunction(){
if (xmlHttp.readyState != 4)
return;
document.getElementById('results').innerHTML = "ready...";
//i commented this out because it just stopped here.
//var codes = eval("("+xmlHttp.responseText+")").postalCodes;
//var nameVar = codes[0].placeName;
//I am trying to see the actual response to see if parsing the json caused it to not work
document.getElementById('results').innerHTML = xmlHttp.responseText;
//document.getElementById('results').innerHTML = nameVar;
}
<body onload="init2()" onunload="unload()">
<h1 id="results">
results
</h1>
</body>
</html>
This is the response i get in the simulator:
Client Error: URL request was filtered.
Yuur request cannot be serviced due to access restrictions. Please contact your System Administrator for further details
Thank you for your help.
08-31-2011 04:07 PM
I have this in my config
<!-- Expose access to all URIs, including the file and http protocols -->
<access subdomains="true" uri="*" />