Jquery不会将数字传递给php

时间:2013-03-03 01:01:24

标签: php jquery ajax-request

每当我尝试提交表单时,它只返回“E”而只返回“E”,我不知道为什么会发生这种情况,任何人都可以帮我解决这个问题吗?

我已经尝试了很多方法,我可以;似乎得到它应该返回的结果

Jquery的:

        $('#edit_ok_btn').click(function(e)
{
    e.preventDefault();
    $('#NoticeBox').hide("slide", { direction: "up" }, 500, function() {
    $('#NoticeBox').show("slide", { direction: "up" }, 500);
    $('#NoticeBox').removeClass()
    $('#NoticeBox').addClass('Box_Working')
    $('#noticeText').html("Processing page...");

    var formData = $('#EditorForm').serialize();
    submitWebPage(formData);



    });
});

    function submitWebPage(formData) {

$.ajax({    
    type: 'POST',
    url: 'PageProcessor.php',       
    data : {'formdata' : formData},
    dataType: 'json',
    cache: false,
    timeout: 7000,
    success: function(data) {   


    $('#NoticeBox').hide("slide", { direction: "up" }, 500, function() {

        if(data.error == false)
        {
            $('#NoticeBox').show("slide", { direction: "up" }, 500);
            $('#NoticeBox').removeClass()
            $('#NoticeBox').addClass('Box_Success')
            $('#noticeText').html(data.msg);
            $('#PageEditor').fadeOut(1000);

            $('#NoticeBox').delay(1000).hide("slide", { direction: "up" }, 500, function() {
            location.reload();
            });



        }
        else
        {
            $('#NoticeBox').show("slide", { direction: "up" }, 500);
            $('#NoticeBox').removeClass()
            $('#NoticeBox').addClass('Box_Error')
            $('#noticeText').html(data.error);
        }

    }); 

    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {

    $('#responder').removeClass().addClass('Box_Error').html('<p>There was an ERROR!<strong></p>');


    }
});

PHP

$PageID         = $_POST['formdata']['EditID'];
$PageTitle      = $_POST['formdata']['PageTitle'];
$PageCategory   = $_POST['formdata']['CategoryList'];
$PageContent    = $_POST['formdata']['elm1'];
$PagePublished  = $_POST['formdata']['PublishPageOption'];

if($PageID == "NEW")
{

mysqli_query("INSERT INTO Web_Pages (Title, HTML, Category, Last_Author, Edit_Date, Published) VALUES ('".$PageTitle."','". $PageContent."','".$PageCategory."','LUX','".date("Y-m-d")."','".$PagePublished."') ");

        $return['error'] = false;
        $return['msg'] = '<i>'.$PageTitle.'</i> has been created successfully.'; 
        echo json_encode($return);
}
else
{
    mysqli_query("UPDATE Web_Pages SET Title = '".$PageTitle."', HTML = '".$PageContent."', Category = '".$PageCategory."', Last_Author='LUX', Edit_Date = '".date("Y-m-d")."', Published = '".$PagePublished."') WHERE ID = '".$PageID."' ");

        $return['error'] = false;
        $return['msg'] = '<i>'.$PageTitle.'</i> has been updated successfully.'; 
        echo json_encode($return);
}

paste-bin link to the source code

2 个答案:

答案 0 :(得分:2)

)查询末尾附近的UPDATE不应该存在,很可能是您忘记编辑的复制/粘贴/编辑的结果。

答案 1 :(得分:0)

我已经厌倦了这个错误!

 data: 'formData',

这将被视为字符串而不是变量

我想你应该做这样的事情

data : {'formdata' : formData}

从php你可以用

获取数据
$_POST['formdata'];