私のAJAX success
関数の中には、if
/else
という文があります。サーバー側からの応答はOKですが、ここで確認するとif
ロジックがelse
ロジックと一緒に実行されます。どちらも同じ時間に実行されますが、これは私にとってはちょっと混乱しています。AJAXの正常な動作でelse文が正常に動作しない場合
$.ajax({
url: 'centre-upload-process2.php',
type: 'POST',
data: formData,
async: false,
success: function (response) {
if(response == 'success') {
$('#centreformupload').hide();
$('#centreformpayment').show();
console.log(typeof response);
} else {
alert("Already present");
console.log(typeof response);
}
},
contentType: false,
processData: false
});
PHP
<?php require_once '../core/class_init.php'; ?>
<?php
$centre_uploads = new dbhandler();
$flag = false;
$client_id = $_POST['client_id'];
$r_id = $_POST['r_id'];
$path = new uploads();
$payment_data = $centre_uploads->all_data('payment_dtls');
$i = 0;
foreach($payment_data as $pd) {
if($payment_data[$i]->fy == input::get('fy')) {
$flag = true;
}
}
if(isset($_POST) && isset($_FILES)) {
//$r_id = $_POST['r_id'];
$inputtext2 = $_POST['inputtext2'];
$inputfile2 = $path->upload_image('inputfile2');
$inputtext3 = $_POST['inputtext3'];
$inputfile3 = $path->upload_image('inputfile3');
$inputtext4 = $_POST['inputtext4'];
$inputfile4 = $path->upload_image('inputfile4');
if(empty($inputtext2) && empty($inputfile2)) {
$inputtext2 = 'NA';
$inputfile2 = 'NA';
}
if(empty($inputtext3) && empty($inputfile3)) {
$inputtext3 = 'NA';
$inputfile3 = 'NA';
}
if(empty($inputtext4) && empty($inputfile4)) {
$inputtext4 = 'NA';
$inputfile4 = 'NA';
}
if(!$flag) {
try{
$centre_uploads->create('payment_dtls' , array(
'r_id' => $r_id,
'client_id' => $client_id,
'fy' => input::get('fy'),
'ay' => input::get('ay')
));
$centre_uploads->create('upload_dtls' , array(
'r_id' => $r_id,
'client_id' => $client_id,
'pan_file' => $path->upload_image('pan_file'),
'bank_file' => $path->upload_image('bank_file'),
'insurance_file' => $path->upload_image('insurance_file'),
'title1' => $inputtext2,
'document1_file' => $inputfile2,
'title2' => $inputtext3,
'document2_file' => $inputfile3,
'title3' => $inputtext4,
'document3_file' => $inputfile4,
'purpose' => input::get('purpose')
));
echo 'success';
}catch(Exception $e){
die($e->getMessage());
}
} else {
echo 'denied';
}
}
応答は1、データがデータベースに挿入されますが、私はまたalert
、ここ応答1に書かれたロジックが動作しない(からは隠さない取得された場合)代わりに私は警戒を得る。
は値 ' '1''または' 1 'のですか?つまり文字列または整数 –
'typeof'を使用して、応答の種類を判断します(Rory McCrossan氏)。 – Ionut
「成功」や「拒否」などのプレーンな文字列を使用しようとしました....まだ使用していません –