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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀