我通过 jQuery 运行一个 ajax 请求,它调用一个 php 函数,每次调用它时都可以工作,我并不是说编写的代码应该可以工作,因为它是正确的,但它可以工作,因为我可以在数据库中看到输出。但是request.fail(function(jqXHR, textStatus){alert('AJAX Error: '+ textStatus);});
返回一个错误(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 是否将此信息详细说明为最终输出?
提前致谢