There is a form in which data is entered, then we click OK and the entered data goes to the javaskiptovy file.
The form on the index.php page
<form id="'.$row['loadName']. '" method="GET"> <table сlass="value"> <tr> <td> <input id="'.$row['loadName'].'-LoadName" name="loadname" type="hidden" value="'.$row['loadName'] ?>'."/> </td> <td> <input id="'.$row['loadName'].'-TestOk" name="testOK" size="10" type="text" value="'.$RowForValues['TestOk'].'"/> </td> </tr> <input class="buttonValue" name="ValueOK" onClick="requestForValue(readDataForValue,\''.$row['loadName'].'\');" type="button" value="OK"/> </form>
Javascript data.js
function requestForValue(callback, id) { var xhr = getXMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { callback(xhr.responseText, id); } }; id_Loadname = id + '-LoadName'; id_TestOk = id + '-TestOk'; var LoadName = document.getElementById(id_Loadname).value; var TestOk = encodeURIComponent(document.getElementById(id_TestOk).value); xhr.open("GET", "AJAX/value.php?LoadName=" + LoadName + "&TestOK=" + TestOk, true); xhr.send(null); }
After that there is an update of this data in the table. But there is a condition where in one case it is necessary to update part of the table (it works), and in another case it is necessary to update the ALL page.
value.php, which is javascript
$dbh = dbConnectForAJAX(); $LoadName = $_GET["LoadName"]; $testok = $_GET["TestOK"]; if (empty($LoadName)) { /*запрос на обновление данных*/ } else { /*запрос на добавление данных*/ echo '<a href="javascript:location.reload()">See new data click here</a>'; }
Tell me how else you can update the index.php page without clicking on the link, and so that it is updated automatically after adding data to the database.