0

问题似乎是它正在触发错误处理程序,而不是成功..

$('#editPlaceForm').submit(function() {
        var placeName = $('#placeName').val();
        $.ajax({
            type: 'POST',
            url: '../FormHandlers/myPlaces.php',
            dataType: 'json',
            data: {update_Place:true, place_Id : placeId, place_Name : placeName },
            success:function(json) {
                var result = JSON.parse(json);
                if (result.success) {
                    $('#editPlaceModal').modal('hide');
                    if (locationsTable) {
                        locationsTable.fnDraw();
                    }
                }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Sorry, an error occurred: Thrown: ' + errorThrown + ', Request: ' + XMLHttpRequest.getAllResponseHeaders().toString() +
                ', TextStatus: ' + textStatus + ', Please try again.');
            }
        });
    });

通过 ajax 调用服务器端:

if (isset($_POST['update_Place'])) {

    $place_id = htmlspecialchars($_POST['place_Id']);
    $place_name = htmlspecialchars($_POST['place_Name']);

    $update = "UPDATE locations SET name='" . $place_name . "' WHERE id =" . $place_id . ";";

    $db->query($update);
    $db->commit();
    $db->close();

    echo json_encode(array('success'=>'Changes were saved.'));
}

非常感谢..................................

4

1 回答 1

2

首先让我印象深刻的是:

url: '../FormHandlers/myPlaces.php',

我不确定“..”的处理位置和方式,但您可以从 php 写入日志以检查脚本文件是否正在运行。

于 2013-06-30T00:06:47.007 回答