2012-06-23 64 views
1

將記錄插入到數據庫時,服務器返回'undefined index:category',錯誤,但仍然成功發佈。PHP + jQuery - 未定義的索引:,但它仍然成功發佈?

$('#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 ] 
    } 
+2

看控制檯。顯示的代碼看起來很好,除了語法...或者在第二個和第三個變量聲明中加上'var',或者用逗號分隔它們 – charlietfl

+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 
}); 

現在嘗試在被崩發什麼又