我有这个脚本代码,它运行正常,
CODE
<script>
function ajob(){
var a3=a.value
var a4=b.value
var a5=c.value
if(a3!='' && a4!=''){
$.ajax({
type:"get",
url:"addj.php?content=" + a3 + "," + a4 + "," + a5
});
lod();
}else{alert('Fill all fields')}
}
</script>
<form>
<table>
<tr><td>Job Name:</td>
<td><input id="a" name="jname" type="text"></td>
</tr>
<tr><td>Job Description:</td>
<td><input id="b" name="jd" style="margin: 2px 0 2px 0;" type="text"></td>
</tr>
<tr><td>Status:</td>
<td>
<select id="c" name="jstat" style="width:100%; height: 26px" >
<option>Active</option>
<option>Not Active</option>
</select>
</td>
</tr>
</table>
</form>
我想知道的是如何知道我的addj.php
文件中是否有错误?这是我的addj.php
addj.php
require 'con.php';
$pieces = explode(",", $_GET['content']);
$jname=$pieces[0];
$jd=$pieces[1];
$jstat=$pieces[2];
$query=mysqli_query($con,"INSERT INTO job(job_name,job_desc,status) values('$jname','$jd','$jstat') ");
如何从我的PHP代码返回失败状态?如何在我的java脚本代码中处理该错误?
答案 0 :(得分:2)
使用此
$.ajax({
type:"get",
url:"addj.php?content=" + a3 + "," + a4 + "," + a5,
success: function(data) { alert("succsess") },
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + " : " + xhr.responseText);
}
});
答案 1 :(得分:2)
使用成功或错误回调函数并将数据输出到控制台。
function ajob(){
var a3=a.value
var a4=b.value
var a5=c.value
if(a3!='' && a4!=''){
$.ajax({
type:"get",
url:"addj.php?content=" + a3 + "," + a4 + "," + a5,
success: function(dataReturn, textStatus, jqXHR) {
console.log(dataReturn);
},
error: function(jqXHR,textStatus,errorThrown){
console.log(textStatus,errorThrown);
}
});
lod();
}else{alert('Fill all fields')}
}
答案 2 :(得分:0)
您可以使用浏览器的控制台。尝试按照一步一步的链接。
Why the Ajax script is not running on IIS 7.5 Win 2008 R2 server?
答案 3 :(得分:0)
您可以使用此代码来捕获任何ajax错误。
$.ajax({
type:"get",
url:"addj.php?content=" + a3 + "," + a4 + "," + a5
}).fail(function(error){
alert(error);
});
希望它有所帮助。