php - Symfony2 is it possible to remove session variable with Javascript? -


when displaying selected products saved in sessions have button want remove specific product if dont need it. can achieve javascript? if not other solutions problem?

i have heard cant set session variables javascript same goes removing them, have heard can ajax remove them?? anyway im displaying products this(for im showing price of product dynamically):

{% item in items %}     <tr>         <td><img width="60" src="{{ asset('bundles/mpfrontend/assets/products/4.jpg') }}" alt=""/></td>          <td>{{ item.model }}</td>         <td>             <div class="input-append"><input class="span1" style="max-width:34px" placeholder="1" id="appendedinputbuttons" size="16" type="text">                 <button class="btn" type="button"><i class="icon-minus"></i></button>                 <button class="btn" type="button"><i class="icon-plus"></i></button>                 <button class="btn btn-danger" type="button" onclick="removeitem(item.id)"><i class="icon-remove icon-white"></i></button>             </div>         </td>         <td>$120.00</td>         <td>$25.00</td>         <td>$15.00</td>         <td>$110.00</td>     </tr> {% endfor %} 

update have done already:

removeaction in controller:

public function removeaction($itemid) {     $session = $this->getrequest()->getsession();     $session->remove();     return $this->render('mpshopbundle:frontend:product_summary.html.twig');     } 

controller routing:

removeitem:   pattern:  /remove   defaults: { _controller: mpshopbundle:homepage:remove } 

the script:

<script>      $(".btn btn-danger").click(function(){           var itemid = $(this).val();         $.ajax({             type: "post",             url: "{{ path('removeitem') }}",             data: { itemid: itemid }         });  </script> 

pressing on button doesnt , im not surprised since first time using javascript guess did wrong?

yes can ajax !

  1. create action in controller remove given product of session.

a sample code :

productcontroller extends controller{    ...     public function removeitemaction($itemid){           //find here session save item.          //and remove          //return response depending on want in format want (json,xml,...)         return new response("...");    } } 

2.create javascript code listen action , send request ajax precedent url. (if use jquery , see $.ajax )

  1. update dom (with deleting right elements or load html want ).

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -