私のajaxに関する問題があります。私のデータベースからデータを追加しています。私はdivを更新しようとしています。時々それはうまくいくが、ときどきそうではない。それはなぜです?。時にはajaxが実行されないことがあります
ここで私のコードは、私は、私のデータベースに追加した後、私のdivをリフレッシュするように、私は関数のaddtoqueueとその成功の中に、私はdivリフレッシャーを入れている。時にはうまくいくこともありますが、時にはそうではありません。何度も試してみましたが、いつも失敗しています。どうして?ここで
function addtoqueue(patient_id) {
if(getClinicID != undefined) {
if (confirm("Are you sure you want to add this in queue?")) {
$.ajax({
url: siteurl+"myclinic/patientaddqueue",
type: "POST",
data: {patient_id:patient_id,clinic_id:getClinicID},
dataType: "JSON",
success: function(data) {
refresh_afterdel(getClinicID);
alert("Patient Successfully Added");
}
});
}
}
else{
alert("There is no clinic selected");
}
}
は完全なコードと私のrefresh_afterdel機能である:
function refresh_afterdel(getClinicID) {
$("#queue").empty();
$.ajax({
url: siteurl+"myclinic/get_patients_refresh/"+getClinicID,
type: "GET",
dataType: "JSON",
success: function(data) {
if(data.length>0) {
$("#queue").empty();
for(i=0;i<data.length;i++) {
$('#queue').append('<div class="col-sm-10">'+'<div class="panel-group">'+'<div class="panel panel-info">'+
'<div class="panel-heading">'+'<h4><a data-toggle="collapse" href="#patientinfo'+data[i]['patient_id']+'">'+data[i]['order_num']+' '+data[i]['patient_lname']+', '+data[i]['patient_fname']+' <span class="fa fa-arrow-circle-o-down pull-right"></span></a></h4>'+
'</div><!-- panel-heading -->'+'<div id="patientinfo'+data[i]['patient_id']+'" class="panel-collapse collapse">'+'<div class="panel-body">'+'<div class="row">'+
'<div class="col-sm-5">'+'<small>Patient ID: <label id="patientID">'+data[i]['patient_id']+'</label></small>'+''+'<button onclick="checkstatus('+data[i]['patient_id']+','+data[i]['queue_id']+');this.disabled=true;" id="btn'+data[i]['patient_id']+'" class="btn btn-success btn-sm ">Check me up</button>'+'<button onclick="checkstatus1('+data[i]['patient_id']+');" id="btn'+data[i]['patient_id']+'" class="btn btn-success btn-xs ">View History</button>'+
'<button onclick="removequeuedoc('+data[i]['queue_id']+');" id="btn'+data[i]['patient_id']+'" class="btn btn-danger btn-xs btnmarg"> Remove </button>'+'</div><!-- col-sm-4 -->'+'<div class="col-sm-6">'+
'<div class="img-patient">'+'<div class="patient-pic" style="background-image: url('+data[i]['patient_photo']+')"></div>'+'</div><!-- img-patient -->'+'</div><!-- col-sm-6 -->'+'</div><!-- row -->'+
'</div><!-- panel-body -->'+'</div><!-- panel-collapse -->'+'</div><!-- panel -->'+'</div><!-- panel-group -->'+'</div><!-- col-sm-10 -->');
};
}
}
});
}
は、今ここで私はrefresh_afterdel addtoqueueボタンをクリックした後に実行されない、ということを示して私のコンソールのスクリーンショットです。私のスクリーンショットの赤いラベルには、refresh_afterdel関数のajaxであるget_patients_refreshが続かなければなりません。ラベルの青を見て、それが私の関数の正しい実行を示しています。
これは単なる非同期操作では不確定な時間がかかりませんか? – evolutionxbox
@evolutionxboxお返事ありがとうございました。私は他の機能で非同期機能を持っていますが、これはscreensUploadでcheckedUpdatesですが、プロセスに影響しますか? 。それは私のaddtoqueueコードの一部ではないのですか? –
ln 2:getClinicIDは値を持つこともnullにすることもできますが、これは決して定義されていないことはありません。 'typeof getClinicID!= 'undefined'を探して、変数が初期化されているかどうかを調べます。 – Chase