2011-08-01 6 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; 
    }); 

VIEWコード

 <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火かぶりに何か間違いがあった? – Rafay

+0

firebugのようなエラーはありません – user855492

答えて

0

何らかの理由で、私は以前にもhtml()を動作させるのに問題がありました。試してください:

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

そのコードでjquery関数のロードがあります... – user855492

0

カートはJSまたはajaxで追加されますか?

cartSubmitcartDisplayは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