0

I am having a problem with Ajax and the CodeIgniter shopping cart. The code works well without AJAX. It seems I am unable to post.

<script type="text/javascript">
    $('ul.products form').submit(function(){

      $('#noticeMessages').empty(); 
        var id = $(this).find('input[name=id]').val();  

  $.ajax({
          type: 'post',
          url:'../books/addProduct',
          data:{id:id}
          }).done(function(data){

              $('#noticeMessages').append('Your product has been added').css('visibility','visible').fadeIn('fast').fadeOut(5000);
              location.reload();

          });
          return false;
    });
</script>
4

1 回答 1

0

尽管这似乎是一个死问题,但我仍然想提出我的建议。这是我会做的

    <script type="text/javascript">
        $('ul.products form').submit(function(){

          $('#noticeMessages').empty(); 
           var id = $(this).find('input[name=id]').val();  
          $.ajax({
              type: 'post',
              url:'../books/addProduct',
              data:{id:id},
              success:function(data){
                $('#noticeMessages').append('Your product has been added').css('visibility','visible').fadeIn('fast').fadeOut(5000);
                  location.reload();
              }
             });
        });
    </script
于 2017-08-10T22:03:26.920 回答