ajax请求php一直执行error函数,数据库操作正常,错误500

 $.ajax({
                  type:"post",
                  url:"../php/insert_articles.php",
                  data:"title=" +tle +"&content=" + cnt +"&time=" +time + "&type=" + type,
                  dataType:"jsonp",
                  jsonp: "jsoncallback",
                  error:function(e) {
                    console.log("出错了:"+e.responseText);
                  },
                  success:function(msg){
                    alert("插入成功!");
                   }
            });


            php:

            $result = $db->query($insert);
    if ($result) {
        $list = array("msg" => "insert successfully");
            echo $_POST['jsoncallback']."(".json_encode($list).")";
    }else {

        $list = array("error" =>"an error ocurred");
            echo $_POST['jsoncallback']."(".json_encode($list).")";
    }
错误截图:
![图片说明](https://img-ask.csdn.net/upload/201605/10/1462849117_171571.jpg)

https://img-ask.csdn.net/upload/201605/10/1462849227_30159.jpg

 目测是没有跨域被jquery转为json数据了,你没有跨域不需要jsonp数据

$.ajax({
                  type:"post",
                  url:"../php/insert_articles.php",
                  data:"title=" +tle +"&content=" + cnt +"&time=" +time + "&type=" + type,
                  dataType:"json",




            $result = $db->query($insert);
    if ($result) {
        $list = array("msg" => "insert successfully");
            echo json_encode($list)//去掉回调
    }else {

        $list = array("error" =>"an error ocurred");
            echo json_encode($list)//去掉回调
    }

我之前试了下json啊,不行的。然后上网搜说可能跨域,改成这样也不行

$.ajax({
type:"post",
url:"../php/insert_articles.php",
data:"title=" +tle +"&content=" + cnt +"&time=" +time + "&type=" + type,
dataType:"json",
error:function(e) {
console.log("出错了:"+e.responseText);
},
success:function(msg){
alert("插入成功!");
}
});

        php:
        $result = $db->query($insert);
if ($result) {
    $list = array("msg" => "insert successfully");
        echo json_encode($list);
}else {

    $list = array("error" =>"an error ocurred");
        echo json_encode($list);
}
也是一样的错误,执行error,https://img-ask.csdn.net/upload/201605/10/1462849227_30159.jpg
郁闷啊啊啊啊

<?php
$title = $_POST['title'];
$content = $_POST['content'];
$time = $_POST['time'];
$type = $_POST['type'];
$say_cont = $_POST['say_cont'];

@ $db = new mysqli('localhost', 'a0424114830', 'xxvaq950228', 'a0424114830');
mysql_query("SET  NAMES 'utf8'");
if ($say_cont != '') {
    $insert = "insert into says (sub_date,say) values ('".date('Ymd')."','".$say_cont."')";
}else {
    $insert = "insert into articles(title, time, content, type) values('".$title."','".$time."','".$content."','".$type."')";
}

$result = $db->query($insert);
if ($result) {
    $list = array("msg" => "insert successfully");
        echo json_encode($list);
}else {

    $list = array("error" =>"an error ocurred");
        echo json_encode($list);
}
$result->free();
$db->close();

?>
整个.php的内容

JS部分改为以下就好。

 $.ajax({
              type:"post",
              url:"../test2/a1.php",
              data:"title=" +tle +"&content=" + cnt +"&time=" +time + "&type=" + type,
              error:function(e) {
                console.log("出错了:"+e.responseText);
              },
              success:function(msg){
                alert("插入成功!");
               }
        });