Php 通过提交按钮获取值时的Jquery问题

Php 通过提交按钮获取值时的Jquery问题,php,jquery,codeigniter,jquery-selectors,Php,Jquery,Codeigniter,Jquery Selectors,JQUERY代码 $('#cartSubmit').click(function() { var product_name = encodeURIComponent($('#product_name').val()); var barcode = encodeURIComponent($('#barcode').val()); var Quantity = encodeURIComponent($('#Quantity').val()

JQUERY代码

  $('#cartSubmit').click(function() {


        var product_name  = encodeURIComponent($('#product_name').val());
        var barcode  = encodeURIComponent($('#barcode').val());
        var Quantity  = encodeURIComponent($('#Quantity').val());


            var postData    =   "product_name="+product_name+"&barcode="+barcode+"&Quantity"+Quantity;
            $.ajax
                ({
                   type: 'POST',
                    url: 'http://localhost/example/index.php/cart/cartoutput',                      
                    data: postData,
                    success: function(html) {
                        //alert(html);
                        $('#cartDisplay').html(html);   

                        }
            });

        return false;
    }); 
视图代码

     <tr><td  align="center" > <input type="submit"  value="SUBMIT" id="cartSubmit"/></td> </tr>

我无法显示输出。代码中的问题是什么?由于某种原因,我过去在工作中也遇到过困难。尝试:

document.getElementById("#cartDisplay").innerHTML = html;

购物车是由JS还是ajax添加的

cartSubmit是否在DOM中的cartDisplay中

尝试更改:

$('#cartSubmit').click(function () {
致:


尝试下面的方法,看看它是否有效,我还制作了一个错误处理程序

$('#cartSubmit').click(function(e) {

   e.preventDefault(); //prevent the default behaviour of the submit

   $.ajax
    ({
      type: 'POST',
      url: 'http://localhost/example/index.php/cart/cartoutput',                      
      data: {product_name:product_name,barcode:barcode,Quantity:Quantity},
      dataType:'html', // i assumed you are returning html
      success: function(html) {
            alert("success");
           $('#cartDisplay').html(html);   
           },
      error:function(jxhr){ // make an error handler 
           alert(jxhr.responseText);
           }
        });       
}); 

您可以使用jquery中的form serialise方法,从$.posttest.php、$testform.serialize;您在firebug中检查过任何错误吗?您在firebug中得到响应了吗?警报是否在内部。成功触发?另外,为您的ajax调用创建一个错误处理程序,它不会触发。。。tat submit按钮不支持workdocument.getElementById[在此错误时中断]未能加载源:我猜submit按钮有问题…如果id=cartSubmit,则无法工作。如果我移除它。。。它显示输出
$('#cartSubmit').click(function(e) {

   e.preventDefault(); //prevent the default behaviour of the submit

   $.ajax
    ({
      type: 'POST',
      url: 'http://localhost/example/index.php/cart/cartoutput',                      
      data: {product_name:product_name,barcode:barcode,Quantity:Quantity},
      dataType:'html', // i assumed you are returning html
      success: function(html) {
            alert("success");
           $('#cartDisplay').html(html);   
           },
      error:function(jxhr){ // make an error handler 
           alert(jxhr.responseText);
           }
        });       
});