PHP + jQuery - 未定义索引:,但它仍然成功发布?

时间:2012-06-23 03:10:30

标签: php jquery jquery-post

将记录插入数据库时​​,服务器返回“未定义的索引:类别”,错误,但仍然成功发布。

   $('#button').click(function(){
    var newvendor    = $('#input_vendor').val();
        newplantcode = $('#input_plantcode').val();
        newcategory  = $('#input_category').val();

$.post("php/addSite.php",
    {vendor: newvendor, 
     plant_code: newplantcode, 
     category: newcategory}, // <--- Error on this line, for some reason...


     function(result){
            console.log("server returned : " + result);
            [ RELOAD THE PAGE ]
     }

1 个答案:

答案 0 :(得分:3)

您几乎在所有代码中都缺少引号:

   $('#button').click(function(){
var newvendor    = $('#input_vendor').val();
var newplantcode = $('#input_plantcode').val();
var newcategory  = $('#input_category').val();

$.post("php/addSite.php",
{vendor: newvendor, 
 plant_code: newplantcode, 
category: newcategory}, // <--- Error on this line, for some reason...


 function(result){
        console.log("server returned : " + result);
        [ RELOAD THE PAGE ]
 }
 //closing the post function
 )
 //closing the click event 
 });

现在再试一次