成功发布后,AJAX检查回数据库

时间:2016-03-24 05:13:50

标签: php ajax webserver

所以我想做的是创建一个系统,在提交后发送短消息并等到用户回复并更改显示。所以AJAX会在一个php文件中发布内容,同时每隔5秒检查另一个php文件,这会返回数据库的结果(如果用户回复短消息,它将返回'1')

这里有一些我的script.js文件

$(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;
});
});`

以下是检查回复的方法

    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);
  }

0 个答案:

没有答案