04-19-2011 04:41 PM
Hello all,
I am new to webworks but willing to learn ![]()
I have a widget that needs to pull some data (text and a pic.) from a Mysql data base over the web.
I have no clue where to start. From what I have read you need to use php json and/or ajax Ok thats nice and all but....I dont how.
So Im looking either for a tutorial or sample code with comments or anything else an I'll attempt to sort it out.
My Project: Using plug in for Visual Studio
Buttons will access the database and will populate an img tag and/or textbox tag
if no internet connection will store the information it previous received.
Right now my buttons code behind is jscript.
I do not need to write data or sort just pull the data down any thing else is just "gravy" ![]()
Thanks for helping
04-20-2011 10:13 AM
My app uses AJAX to get PHP to access the MySQL data. a simple | delimited response.
Otherwise there's the WebDB you can use on the playbook (and BB OS6 I think)
WebDB uses SQL-like syntax, of course you'd need to create a javascript page to create the DB
04-21-2011 01:28 PM
OK so the Ajax is part of the widget. Any pointers to a good guild on how that is done?
04-21-2011 01:31 PM
Not sure of any guides. I use w3schools.com for the basic ajax syntax. You don't need the cross browser stuff since it's supposed to all be the same for webworks.
For how you parse the data, it's up to you. I use | delimited and extract it on the javascript side. I use that character since it's one of the least likely used.
04-21-2011 03:48 PM
Please take a look at this code:
What part of the red code do you need for the blackberry browser and I don't reconize where it is stating the http to connect to. This is from the link you suggested w3school.com-- http://www.w3schools.com/PHP/php_ajax_database.asp
Thanks for helping this newbie out.
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
04-21-2011 04:03 PM
function showUser(str)
{
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
}
}
//Change getuser.php to http://www.wateva.com/getstuff.php
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
Removed the condition for IE7/IE6 etc since BB uses the current standard for AJAX.
Also, the PHP/ASP page might require a special header for cross domain permissions. Took me a while to figure it out.
Not at home so don't have access to that, but I'll try to send it as soon as I can. Otherwise google for security cross domain header or something
04-21-2011 07:20 PM
awsome thanks for the help so far
04-26-2011 03:57 PM
ok so here is the code im using to populate a div tag in a webworks html form.
But its not working in the simulator or in firefox. Just nothing happens on the button click not even a crash.
Anyone see what I'm doing wrong?
SCRIPT
function Button2_onclick(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlht
}
}
//Change getuser.php to http://www.wateva.com/getstuff.php
xmlhttp.open("GET","http://ishopstark.com/mobileapp.php?category=1"+str,true);
xmlhttp.send();
}
PHP PAGE
<?php
$app = $_REQUEST['appid'];
$cat = $_REQUEST['category'];
switch ($cat){
case 1 :
echo "<p>category 1</p>";
echo "<img src='/images/bannerads/hales_bannerad.gif'><br>
<a href=\"mobileapp.php?category=2\">Click here to test and see if once your page is loaded it will jump from link to link inside the app on this same page</a>";
echo"<p>Lorem ipsum dolor sit amet, consectetur </p>";
break;
case 2 :
echo "<p>category 2</p>";
echo "<img src='/images/bannerads/lehr_bannerad.gif'><br>";
echo"<p>Lorem ipsum dolor sit amet, consectetur </p>";
break;
default :
echo "<p>Default</p>";
echo"<p>Lorem ipsum dolor sit amet, consectetur </p>";
break;
}
?>
04-26-2011 04:27 PM
Where are you binding Button2_onclick to the button click event. If nothing's happening, it sounds like you haven't connected the two. try putting something simple like
alert("Button Clicked");
as the first line of your Button2_onclick function. Once we know everything's wired up properly it's easier to help.
Also, I don't want to discourage you from posting in the forums, or even web works development in general, but this is a pretty general question, so you may be better served by reading some JavaScript and Ajax tutorials before you go any further.
04-26-2011 04:30 PM