i want to post a variable data to ajax post this is my html code
<tr>
<td class="text-right">Payment ID:</td>
<td>variable</td> // variable that i want to post
</tr>
and this is my java script code
var ajax_call = function() {
$.ajax({
type:"post",
url:"request-handler.php",
data:{
data:"Payment ID"
}
});
};
var interval = 5000; // where X is your every X minutes
setInterval(ajax_call, interval);
now i want to post the variable that between td tags in the ajaxpost
</div>
<tr id="rowID">
<td class="text-right">Payment ID:</td>
<td>variable</td> // variable that i want to post
</tr>
and in your javascript
var ajax_call = function() {
$.ajax({
type:"post",
url:"request-handler.php",
data:{
var Row = document.getElementById("rowID");
var Cells = Row.getElementsByTagName("td");
data:Cells[1].innerText
}
});
};
EDIT: You can directly use var cells = document.getElementsByTagName("td"); as well. OR set and id to cell <tr > <td class="text-right">Payment ID:</td> <td id="columnID">variable</td> // variable that i want to post </tr>
data:{document.getElementById("columnID")}
Set an id on that cell so your js is easily readable, then just use jQuery to access the text.
var ajax_call = function() {
$.ajax({
type: "post",
url: "request-handler.php",
data: {
paymentId: $('#payment-id').text();
// access this on the php server using: $_POST['paymentId'];
}
});
};
var interval = 5000; // where X is your every X minutes
setInterval(ajax_call, interval);
<tr>
<td class="text-right">Payment ID:</td>
<td id="payment-id">variable</td>
<!-- variable that i want to post -->
</tr>
</div>