JQuery POST在PHP脚本中显示为空数组

时间:2013-03-19 19:49:02

标签: php javascript ajax post

在JS文件中,我正在执行此功能:

$(function() {
    $(".button").click(function() {

        //get the button's ID (which is equal to its row's report_id)
        var emergency = this.id;
        var button = this.attributes['name'].value;
        var dataString = 'reportid=' + emergency;

        alert(dataString);
        if (button == "clockin") {
            $.ajax({
                type: "POST",
                url: "/employeetimeclock.php",
                data: dataString,
                success: function() {
                    window.location = "/employeetimeclock.php";
                }
            });
        } else if (button == "closereport") {
            var r = confirm("Are you sure you want to close this report?\nThis action CANNOT be undone!");
            if (r == true) {
                $.ajax({
                    type: "POST",
                    url: "/closeemergencyreport.php",
                    data: dataString,
                    success: function() {
                        alert("Report Successfully Closed!");
                        window.location = "/closeemergencyreport.php";
                    },
                    error: function() {
                        alert("An error has occured, the report was not closed");
                    }
                });
            } else {
                alert("Report was not closed.");
            }
        }
    });
});

对于else if(to closeemergencyreport.php),该php脚本中的代码如下:

<?php

require_once("models/config.php");
require_once("models/header.php");
require_once("models/dbconnect.php");


$reportid = $_POST['reportid'];


var_dump($_POST);


$sql = "UPDATE emergency_report SET report_closed = '1' WHERE report_id IN ( $reportid )";
//execute and test if succesful
$result = mysql_query($sql) or die(mysql_error());
if($result){
} else{
}
?>

我在其他3个页面上做了同样的事情并且它完美无缺地工作但是这给我带来了麻烦,在那个PHP脚本上VAR_DUMP说它正在返回一个空数组。我已经阅读并重新阅读了大约一个半小时的代码,所以我觉得我已经烧坏了,需要有一个外部视图。我已经遍布整个网站,没有人有一个适合我的解决方案。

我知道它的发布是因为火灾错误在表单的页面上显示了javascript运行: http://i.imgur.com/hItdVU1.png(抱歉无法发布图片)

0 个答案:

没有答案