2011-08-01 57 views
0

jQuery代碼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> 

我不能夠顯示輸出。代碼中有什麼問題

+1

可以使用的形式還原序列化方法從jquery,從http://api.jquery.com/jQuery.post'$ .post(「test.php」,$(「#testform」)。serialize());' – Kumar

+0

你有沒有ch在firebug ecked任何錯誤? – Rafay

+0

在螢火蟲中沒有錯誤 – user855492

回答

0

由於某些原因,我在過去也遇到過難以使用html()的問題。試試:

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

在該代碼中有負載的jquery函數... – user855492

0

是否通過JS或ajax添加了購物車?

cartSubmit裏面的cartDisplay在DOM中嗎?

嘗試改變:

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

要:

$('#cartSubmit').live ('click', function() { 
+0

document.getElementById( [打破此錯誤]無法加載源:http://localhost/example//js/example.js – user855492

0

嘗試以下,看看它的工作原理,還我已經犯了一個錯誤處理程序

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

我想提交按鈕的問題......它不工作,如果id =「cartSubmit」.. .if我刪除它...它顯示輸出 – user855492