Aim is to set (change) html hidden input field value to 0 after successful execution of ajax.
At first decided on ajax success to define variable and latter to use outside ajax.
But read (JQuery - How to use the return value of an ajax call outside that ajax call) that it is impossible.
Need to find some solution.
Below is code
Ajax (as an example)
<script language="JavaScript" type="text/javascript">
function ajax_post(){
if (window.XMLHttpRequest)
{
var hr = new XMLHttpRequest();
}
else
{
var hr = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "_autosave.php";
var sabt = document.getElementById("date_day1").value;
var prao = document.getElementById("amount1").value;
var vars = "date_day1="+sabt+"&amount1="+prao;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
Here I decided to define variable to use it outside ajax. As read this does not work because script runs over the variable and reaches outside ajax variable before the ajax variable is set.
var ajax_post_success = 1;
Remaining part of code
}
}
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
</script>
Then latter (if ajax success set value to 0)
<input type="hidden" name="is_row_changed1" id="is_row_changed1" value="" >
<script>
$(document).ready(function() {
if(ajax_post_success == 1) {
document.getElementById('is_row_changed1').value = 0;
}
});
</script>
Aim of all this is following.
I plan to use table with 10 rows and 19 input fields in each row.
If user enters something in any of fields, value of hidden input field changes to 1 (this is ok).
Then with ajax insert/update user input.
After successful insert/update set hidden field value to 0.
On each php insert/update execution check if hidden field value is 1. If value is 1 insert/update the row. If value is 0 do nothing with the row. Insert/update only rows which hidden field value is 1.
That is the aim of the question.
What would be solution?