button with httpREQUEST, SQL query, PHP and JAVASCRIPT

Zealot

New Member
First, sorry for my english.Ok.. the code is a mess because I try many different ways.if you want to try the code localhost, you can easily replace my database query by php variables + ive put the major string and text in english for an easier understandingWhat im trying to do looks like simple.. but for me javascript isnt making me life simple! :PI want to have a simple button, which change (toggle) a sql value onclick and then the value of the button change for the new sql value.. if no sql errors.Exemple of what I expect:
  • I retrieve a value form a specific row in the database: RAIN = 'yes'
  • Now when the page load, if the RAIN value = http://stackoverflow.com/questions/15856778/yes, the button value will be set to RAIN, else value will be NO RAIN.
  • We suppose the row value RAIN is set to 'yes' -> when I click on the button, the row value will be set to 'no' and then if no sql errors, button value will change for NO RAIN. and etc..
What i've done for now is an ajax json request with httprequest and GET. All is working fine except after I clicked once on the button.. I need to refresh my page to get the button working again. I know this is probably not the best way to code it.. because theres a lot of if and else for nothing maybe.. but I try as I can because im a javascript beginner.. :P the 2 files are just testing codes file so dont worry about the $('#toggle').bootstrapSwitch('setState', false); this is just a bootstrap switch button I was testing by the same time. Ok so here is the code.. LOLthis is my json.php file which is the main page of the code\[code\] <?php/* Connection DATABASE */include($_SERVER['DOCUMENT_ROOT']."/include/config/config.inc.php");/* selection de la db */$db_connect = mysql_select_db("dbx", $con);$result_client = mysql_query("SELECT * FROM clients WHERE id='1'");$row_client = mysql_fetch_array($result_client);//get the value for the button on load pageif($row_client['rain'] == "yes"){ $button_state_rain = "RAIN NOW";}else{ $button_state_rain = "NO RAIN";}?><!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" /><script>function json_query(){ //le if est pou des raison de compatibilit
 
Back
Top