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

标签 php jquery jquery-post

向数据库插入记录时,服务器返回“ undefined index :类别”错误,但仍然发布成功。

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

最佳答案

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

   $('#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 
 });

现在再试一次

关于PHP + jQuery - 未定义索引 : , 但它仍然成功发布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11166498/

相关文章:

php - 一种将数组及其键保存到数据库的有效方法

javascript - 如何用纯 JavaScript 编写 $ ("#content").height() ?

一个类的 jQuery 选择器,后跟一个空格,然后是另一个类

internet-explorer - Jquery Ajax 请求未在 IE 中发送

php - 如何在 Laravel 5 中创建包?

php - Guzzle Curl 错误 60 SSL 无法获取本地发行者

php - PHP 对象序列化有多安全,跨页面传递是否安全? (使用 phpXMLrpc)

jQuery 发现 "selector"

javascript - 访问 $.post jQuery 中的变量

jQuery - 添加到收藏夹