weixin_33698043 2014-06-26 07:48 采纳率: 0%
浏览 68

$ .ajax调用中的错误

I have an $.ajax call in one of my pages that links to a simple php page.

I am getting my alert for the error: property. I am not getting anything back in the errorThrown variable or in the jqXHR variable. I have never done this kind of thing before and i am not seeing what is wrong with my page.

JQuery $.ajax call :

    function jsonSync(json) {
        $.ajax({
            type: 'POST',
            url: 'http://www.cubiclesandwashrooms.com/areaUpdate.php',
            dataType: 'json',
            data: json,
            context: this,
            success: function () {

            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Error has occured! 
 ERR.INDEX: Sync failed, ' + jqXHR.responseText + ';' + textStatus + ';' + errorThrown.message);
                return false;
            }
        });

And this is my PHP Page :

$JSON = file_get_contents('php://input');
$JSON_Data = json_decode($JSON);

//handle on specific item in JSON Object
$insc_area = $JSON_Data->{'insc_area'};

//mysqlite connection.open() equivilent
$insc_db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno($insc_db)) {
    die('Could not connect: ' . mysql_error());
    echo "Failed to connect to MySql: " . mysqli_connect_error();
    //mysqli_close($insc_db);
}

//$insc_area.length equivilent
$insc_area_size = sizeof($insc_area);

//cycle through reult set
for ($i = 0; $i < $insc_area_size; $i++) {

    //assign row to DataRow Equivilent
    $rec = $insc_area[$i];

    //get specific column values
    $area = $rec->{'area'};
    $id = $rec->{'srecid'};

    //sqlcommand equivilent
    $query = "SELECT * FROM insc_products WHERE id='$id' LIMIT 1";
    $result = mysqli_query($insc_db, $query);
    $num = mysqli_num_rows($result);

    //dataReader.Read equivilent
    while ($row = $result->fetch_array()) {

        $query = "UPDATE insc_products SET area='$area' where id = '$id'";
        $res = mysqli_query($insc_db, $query);

        //checking if update was successful
        if ($res) {
            // good
            error_log('user update done');
            echo 'update was successful';
        } else {
            error_log('user update failed');
            echo 'error in update';
        }
    }
}
echo 'testing php';
  • 写回答

2条回答 默认 最新

  • 喵-见缝插针 2014-06-26 07:51
    关注

    dataType: 'json'

    means: give me json back. your PHP file isn't returning json formatted data

    similar question: jQuery ajax call returns empty error if the content is empty

    to buid a json response fill an array in the php file with the return information and use echo json_encode($array); at the end of the file. if you are using dataType:'json' because the code is copy/pasted, and you won't need the response to be in json format, simply remove this option...

    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同