So what I want to do is creating a system which send a short message after submit and wait to until user to reply and change the display. So the AJAX will post something to one php file while also checking to another php file each 5 seconds which is returning the result of the database (if the user replies the short message it will return '1')
here some of my script.js file
$(document).ready(function(){
$("#submit").click(function(){
var price = $("#price").val();
var nohp = $("#nohp").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'price='+ price + '&nohp='+nohp;
var loading ='loading.php?price='+ price + '&nohp='+ nohp;
if(price==''|| nohp=='')
{
alert("Please Fill All Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "send_beli_isentric_t.php",
data: dataString,
cache: false,
success: function(result){
$("#loading").load(loading);//here will be send to loading page wait until user's reply
check_send_success();//check if user replies success or not
}
});
}
return false;
});
});`
and here is how to check reply
function check_success(dataStr,nohp,harga){
setInterval(function(){
$.ajax({
type:"POST",
url:"check.php",
data: dataStr,
cache:false,
success: function(result){
//if the result is 1
if(result == 1){
//show the transaction success
$('#loading').html('<p>62'+ nohp + ':Transaction Success</p>');
//clearInterval(loadingIntervalId);
}else{
//show the transaction fail
$('#loading').html('<p>62'+ nohp + ':Transaction Fail</p>');
//clearInterval(loadingIntervalId);
}
}
});
},5000);
}