And here is the main Gears page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JSON to SQLITE</title> </head>
<body> <script src="http://localhost/Impact Gears Offline/gears_init.js"></script> <script language="javascript" type="text/javascript"> var script_active=0; function checkonlinestatus() { if(navigator.onLine) { return true; } else { return false; } } function floadfromdatabase() { if (script_active==1) { settext("Error: Script is already running...","program_status"); return false; } if (checkonlinestatus()==false) { settext("Error: Not online. Network error?","program_status"); return false; } // settext("Reading data from main DB...","program_status"); script_active=1; var link="http://localhost/impact/tml_php/tml_mysql_to_json.php?q=" + Math.floor(Math.random() * 100000); data=""; var request = google.gears.factory.create('beta.httprequest'); request.open('GET', link); request.onreadystatechange = function() { if (request.readyState == 4) { try { data=request.responseText; } catch (ex) { alert("Status: Error reading data from main DB","program_status"); //settext("Status: Error reading data from main DB","program_status"); active_script=0; return; } if (data.length==0) { alert("No data found. Network error?"); //settext('No data found. Network error?',"program_status"); } else { alert("Status: "+data.length+" byte(s) read from main DB, adding data to local DB"); //settext("Status: "+data.length+" byte(s) read from main DB, adding data to local DB","program_status"); insertdata(data); } } }; request.send(serverresponse); } function insertdata(data) { var workerPool = null; workerPool = google.gears.factory.create('beta.workerpool'); // handle messages from the worker workerPool.onmessage = function(a, b, message) { alert(message.body); //Show message received from workerPool } try { var childWorkerId = workerPool.createWorkerFromUrl('databaseworker2.js'); workerPool.sendMessage(data, childWorkerId); } catch (e) { alert('Could not create workerpool: ' + e.message); } return; } </script> <form action="" method="get" name="form1"> <input name="toDB" value="click" type="button" onClick="floadfromdatabase();" /> </form> </body> </html> > -----Original Message----- > From: [email protected] [mailto:[email protected]] > On Behalf Of Oblygre > Sent: Tuesday, February 17, 2009 8:12 AM > To: Gears Users > Subject: [gears-users] Re: workerpool messages > > > Please post the relevant code so its easier for us to help you > :--)))))))))) > Olav > > > On Feb 16, 12:36 pm, "meerkat" <[email protected]> wrote: > > Hi, > > In my main Gears file I have "alert(data);" and the correct data is > there. I > > get the message "Status: "36117 byte(s) read from main DB, adding data > to > > local DB". > > > > Where do I set " var serverresponse=message.body;" If I put it in > > databaseworker.js I get "message is not defined" error. > > Thanks, meerkat > > > > > > > > > -----Original Message----- > > > From: [email protected] [mailto:gears- > [email protected]] > > > On Behalf Of Oblygre > > > Sent: Monday, February 16, 2009 6:03 AM > > > To: Gears Users > > > Subject: [gears-users] Re: workerpool messages > > > > > You get the error beacuse data in your serverresponse variable > > > contains not valid json data. > > > Try > > > wp.sendMessage("Error: No valid data found. Data > > > was:"+serverresponse,message.sender); > > > to have a look at the data your getting. > > > Serverresponse varaiable must be set to the recived data from the > > > parent script. > > > In my example over, serverresponse must be set to message.body > > > var serverresponse=message.body; > > > > > On Feb 15, 8:01 pm, "meerkat" <[email protected]> wrote: > > > > OK, now getting wp messages on screen. > > > > In main html file I am getting "undefined" for > > > "workerPool.sendMessage(data, > > > > childWorkerId)". > > > > > > I have done, for testing purposes, alert(data); and > > > > alert(childWorkerId); > > > > > > and they are returning the correct values individually. So why is > > > > "console.log(workerPool.sendMessage(data, childWorkerId));" getting > > > > "undefined"? > > > > > > In databaseworker.js I now have: > > > > " > > > > try > > > > { > > > > eval("dataarr="+serverresponse); > > > > > > } > > > > catch (ex) > > > > { > > > > wp.sendMessage("Error: No valid data > found..",message.sender); > > > > return; > > > > }" > > > > > > And I am getting "Error: No valid data found.." message. > > > > > > Any more suggestions? > > > > meerkat > > > > > > > -----Original Message----- > > > > > From: [email protected] [mailto:gears- > > > [email protected]] > > > > > On Behalf Of Oblygre > > > > > Sent: Sunday, February 15, 2009 2:52 PM > > > > > To: Gears Users > > > > > Subject: [gears-users] Re: workerpool messages > > > > > > > A suggestion how to return and show messages from a workerpool. > > > > > Also a replay to your other message :-)) > > > > > > > In your databaseworker.js: > > > > > var wp = google.gears.workerPool; > > > > > wp.onmessage = function(a, b, message) { > > > > > wp.sendMessage("Ok, started....",message.sender); //Send message > bak > > > > > to caller > > > > > .. other code > > > > > > > In your calling script: > > > > > workerPool = google.gears.factory.create('beta.workerpool'); > > > > > workerPool.onmessage = function(a, b, message) { > > > > > alert(message.body); //Show message recived from workerPool > > > > > } > > > > > var childWorkerId = > > > > > workerPool.createWorkerFromUrl('databaseworker.js'); > > > > > workerPool.sendMessage(data, childWorkerId); > > > > > > > On Feb 14, 8:08 pm, meerkat <[email protected]> wrote: > > > > > > Hello, > > > > > > Where and how can I as a programmer see the workerpool messages? > > > > > > > > I can't see anything in the Firebug console? Do I explicitly > have to > > > > > > write to this console? How do I do that? Or is there a better > > > > > > solution? > > > > > > Thanks. > > > > > > meerkat
