Wednesday, 15 July 2015

php - JavaScript doesn't update Internet Explorer if same query sent before -



php - JavaScript doesn't update Internet Explorer if same query sent before -

i'm working on checklist users can set 4 diffent alternative on while cliking on it. when click once, greenish , display "ok", 1 time more, gray , "n/a", white , empty. after starts 1 time again greenish , "ok" each time update database value 1,2,3 or 0 each possibilities. javascript works great, color , text updated correctly in browsers everytime click on update of database, works well, until go white or 0 in database. click, updates 1, 2, 3, 0, when should 1 doesn't update anymore. don't have issue chrome.

here javascript code :

function checklog(tdcheck,id){ var url; var color; var status; var text; xmlhttp=getxmlhttpobject(); if (xmlhttp==null) { alert ("browser not back upwards http request"); return; } var td = document.getelementbyid("tdcheck"+tdcheck); if(td.style.backgroundcolor == "white"){ color = "green"; status = "1"; text = "ok"; } else if(td.style.backgroundcolor == "green"){ color = "grey"; status = "2"; text = "n/a"; } else if(td.style.backgroundcolor == "grey"){ color = "red"; status = "3"; text = "ko"; } else if(td.style.backgroundcolor == "red"){ color = "white"; status = "0"; text = ""; } url="checklist/checklog.php"; url=url+"?id="+id+"&tdcheck="+tdcheck+"&status="+status; xmlhttp.onreadystatechange=statechanged; xmlhttp.open("get",url,false); xmlhttp.onreadystatechange = function() { if(xmlhttp.readystate == 4 && xmlhttp.status == 200){ alert(xmlhttp.responsetext); } } xmlhttp.send(null); document.getelementbyid("tdcheck"+tdcheck).style.backgroundcolor=color; document.getelementbyid("tdcheck"+tdcheck).innerhtml=text; }

checklog.php :

<?php seek { $pdo_options[pdo::attr_errmode] = pdo::errmode_exception; $bdd = new pdo('mysql:host=localhost;dbname=dbname', 'database', 'password'); } catch(exception $e) { die('erreur : '.$e->getmessage()); } if(isset($_get["tdcheck"])) { $bdd->exec("update checklistnew set ".$_get["tdcheck"]." = '".$_get["status"]."' id = '".$_get["id"]."'"); } ?>

i have removed pdo in case issue , utilize mysql_connect, still same. using response text, monitor sql request , can see 1 thing :

i click first, query looks :

update checklistnew set a2 = '1' id = '4' update checklistnew set a2 = '2' id = '4'

then if update php file "update checklistnew set td = number id = 'idnum'" (i added quotes arround id)

update checklistnew set a2 = '4' `id` = '4' update checklistnew set a2 = '0' `id` = '4' update checklistnew set a2 = '1' id = '4' update checklistnew set a2 = '2' id = '4'

notice kept previous query. :)... think there there.

i'll appreciate help!

ie caches xmlhttprequests utilize method, it's that.

you can 1 of many things, simplest being:

don't utilize updating; switching post prepare problem; utilize send("post", ...) instead of send("get", ...), not need alter on php side (because post requests $_get gets populated query parameters); add random url. simple unused parameter random number. like: url=url+"?id="+id+"&tdcheck="+tdcheck+"&status="+status + "&random=" + math.random()

warning: php script extremely unsafe, has multiple sql injection vulnerabilities. prepare now. (see how prevent sql injection in php?)

php javascript mysql internet-explorer

No comments:

Post a Comment