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 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式