呼び出すたびに機能するphp関数を呼び出すjQueryを介してajaxリクエストを実行します。これは、記述されたコードが正しいため機能するという意味ではありませんが、データベースで出力を確認できるため機能します。ただしrequest.fail(function(jqXHR, textStatus){alert('AJAX Error: '+ textStatus);});
、 error( parseerror
) を返します。これが私のコードです。
$('#createtk').click(function(){
var tit=$('#title').val();
var prio=$('#priority').val();
var wsurl=$('#wsurl').val();
var dep=$('#dep').val();
var message=CKEDITOR.instances.message.getData().replace(/\s+/g,' ');
if(tit.replace(/\s+/g,'')!='' && prio.replace(/\s+/g,'')!='' && dep.replace(/\s+/g,'')!='' && wsurl.replace(/\s+/g,'')!='' && message.replace(/\s+/g,'')!=''){
var request= $.ajax({
type: 'POST',
url: '../php/function.php',
data: {act:'create_ticket',tit:tit,prio:prio,dep:dep,wsurl:wsurl,contp:$('#contype').val(),ftpus:$('#ftpus').val(),ftppass:$('#ftppass').val(),message:message},
dataType : 'json',
success : function (data) {
alert('1');
if(data[0]=='Created'){
alert('2');
window.location = "<?php echo dirname(curPageURL()); ?>";
}
else
alert(data[0]);
}
});
request.fail(function(jqXHR, textStatus){alert('AJAX Error: '+ textStatus);});
}
else
alert('Form Error - Empty Field');
});
そして、これはphp関数です(プレゼンテーションで申し訳ありませんが、exeで動作するため、情報のためにこれを置きます):
else if(isset($_POST['act']) && isset($_SESSION['name']) && $_POST['act']=='create_ticket'){ //controllare
$message=(preg_replace('/\s+/','',$_POST['message'])!='')? htmlentities(preg_replace('/\s+/',' ',$_POST['message']),ENT_QUOTES,'UTF-8'):exit();
$tit=(preg_replace('/\s+/','',$_POST['tit'])!='')? htmlentities(preg_replace('/\s+/',' ',$_POST['tit']),ENT_QUOTES,'UTF-8'):exit();
$dep=(is_numeric($_POST['dep']))? (int)$_POST['dep']:exit();
$prio=(is_numeric($_POST['prio']))? $_POST['prio']:exit();
$wsurl=(preg_replace('/\s+/','',$_POST['wsurl'])!='')? htmlentities(preg_replace('/\s+/',' ',$_POST['wsurl']),ENT_QUOTES,'UTF-8'):exit();
$contype=(is_numeric($_POST['contp']))? (int)$_POST['contp']:exit();
$ftppass=(preg_replace('/\s+/','',$_POST['ftppass'])!='')? htmlentities(preg_replace('/\s+/',' ',$_POST['ftppass']),ENT_QUOTES,'UTF-8'):'';
$ftpus=(preg_replace('/\s+/','',$_POST['ftpus'])!='')? htmlentities(preg_replace('/\s+/',' ',$_POST['ftpus']),ENT_QUOTES,'UTF-8'):'';
if(preg_replace('/\s+/','',$_POST['message'])!=''){
$mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
$stmt = $mysqli->stmt_init();
if($stmt){
$query = "INSERT INTO ".$SupportTicketsTable."(`department_id`,`user_id`,`title`,`priority`,`website`,`contype`,`ftp_user`,`ftp_password`,`created_time`,`last_reply`) VALUES (?,?,?,?,?,?,?,?,?,?)";
$prepared = $stmt->prepare($query);
if($prepared){
$date=date("Y-m-d H:i:s");
if($stmt->bind_param('iisissssss', $dep,$_SESSION['id'],$tit,$prio,$wsurl,$contype,$ftpus,$ftppass,$date,$date)){
if($stmt->execute()){
$tkid=$stmt->insert_id;
$ip=retrive_ip();
$refid=uniqid(hash('sha256',$tkid.$tit),true);
$query = "UPDATE ".$SupportTicketsTable." SET enc_id=? WHERE id=? ";
if($prepared = $stmt->prepare($query)){
if($stmt->bind_param('si', $refid,$tkid)){
if($stmt->execute()){
$query = "INSERT INTO ".$SupportMessagesTable."(`user_id`,`message`,`ticket_id`,`ip_address`,`created_time`) VALUES (?,?,?,?,?);";
if($prepared = $stmt->prepare($query)){
if($stmt->bind_param('isiss', $_SESSION['id'],$message,$tkid,$ip,$date)){
if($stmt->execute()){
$selopid=retrive_avaible_operator($Hostname, $Username, $Password, $DatabaseName, $SupportUserPerDepaTable, $SupportUserTable, $dep);
if(is_numeric($selopid)){
$query = "UPDATE ".$SupportTicketsTable." a ,".$SupportUserTable." b SET a.operator_id=?,a.ticket_status='1',b.assigned_tickets (b.assigned_tickets+1) WHERE a.id=? AND b.id=? ";
if($prepared = $stmt->prepare($query)){
if($stmt->bind_param('iii', $selopid,$tkid,$selopid)){
if($stmt->execute()){
echo json_encode(array(0=>'Created'));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
echo json_encode(array(0=>$selopid));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
}
else
echo json_encode(array(0=>mysqli_stmt_error($stmt)));
$mysqli->close();
}
else
echo json_encode(array(0=>'Empty Message'));
}
この関数は別の php 関数 ( retrive_avaible_operator
) を呼び出しますretrun
が、これが問題なのだろうかと思います。AJAX/PHP はこの情報を最終出力として詳しく説明しますか?
前もって感謝します