Hi all..
I want to retrieve Data from Web Server..
For example U can say Database..
I have items stored in my DB... If I have 10 books in the DB... Cx picks when in the App,
I want a message to be displayed there as "Number of stocks as only 10".....
This is to check the availability of the Product in the DB...
Please any one guide me with a code......
3 Answers
Accepted Answer
Hi Suresh! you can use this code in titanium end to fetch data from XML.
-you have write CMS at php end which will update the XML.
var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { Ti.API.info('twitter xml ' + this.responseXML + ' text ' + this.responseText); var doc = this.responseXML.documentElement; var elements = doc.getElementsByTagName("screen_name"); var screenName = elements.item(0); Ti.API.info("screenname = " + screenName.text); var screenname = Ti.UI.createLabel({ textAlign:'center', height:'auto', width:'auto', top:20, text:screenName.text }); Ti.UI.currentWindow.add(screenname); var textarea = Ti.UI.createTextArea({borderRadius:5,borderWidth:2,borderColor:'#999',backgroundColor:'#111',color:'yellow',bottom:10,left:10,right:10,height:300,font:{fontFamily:'courier',fontSize:10}}); textarea.value = this.responseText; Ti.UI.currentWindow.add(textarea); }; // open the client xhr.open('GET','http://twitter.com/statuses/show/123.xml'); // send the data xhr.send();
For getting data from web server you need to create web service on server end, you can either make get or post service which can return json or xml as per your requirement. In your mobile app you can call service using create http client object and can get json or xml in response.
here is php code for you Suresh!
//Suppose I am passing User Email (Known) $query = "SELECT * FROM login WHERE email_id='$userEmail'"; $result = mysql_query($query) or die(mysql_error()); $out_put = ''; if (mysql_num_rows($result) > 0) { $login_selected = mysql_fetch_array($result); $out_put.='<loginInfo>'; $out_put.='<userId>' . stripslashes($login_selected['id']) . '</userId>'; $out_put.='<userName>' . stripslashes($login_selected['first_name']) . ' ' . stripslashes($login_selected['last_name']) . '</userName>'; $out_put.='<userEmail>' . stripslashes($login_selected['email_id']) . '</userEmail>'; $out_put.='</loginInfo>'; } else { $out_put.='<loginInfo>'; $out_put.='<userId>empty</userId>'; $out_put.='<userName>empty</userName>'; $out_put.='<userEmail>empty</userEmail>'; $out_put.='</loginInfo>'; } $file_handler = fopen('your_desired_file_name.xml', 'w'); fwrite($file_handler, $out_put); fclose($fh);
Your Answer
Think you can help? Login to answer this question!