vendredi 2 décembre 2016

How to refresh bootstraps model using ajax call..?

Actually I am trying to refresh model pop-up for getting session value.which is every time different.but its not working proper.I am working on laravel fremework.

anchor link :

 <a class="btn btn-primary btn-sm btn-sm1 btn_modal"  data-backdrop="static" data-keyboard="false" data-id="@,@,@,@"   style="margin-top:0px;">

My ajax call for which is open in class call

 $(document).on("click", ".btn_modal", function () 
      { 
         var passedID=$(this).data('id');

        var string = passedID;
        var array = string.split(",");

        $('#productid').data('id', array[0]);
        $('#productname').text(array[1]);
        $('#productdescription').text(array[2]);
        $('#productprice').text(array[3]);
        $('#mainvalue').val(array[3]);
        // $("#addmodel").load(location.href + "#addmodel");


        var a = array[0];

        $.ajax({
                url: '<?= URL:: to('pdtsession') ?>',
                type: 'GET',
                async : false,
                data : {
                            'productid' : a,
                       },

                success: function(html)
                 {

                    if(html == 0)
                    {

                        $("#addmodel").modal('show');
                    }
                    else
                    {
                       alert('error');
                    }
                 },


            });


      });

controller code:

public function pdtsession(Request $request)
{ 

      session()->flush();
      $postuser1 =  $request->all();
      $request->session()->put('pdt_id',$postuser1['productid']);
      if(session()->has('pdt_id'))
      {
        return 0;
      }
      else
      {
        return 1;
      } 


}

public function destroypdt1()
{
    session()->forget('pdt_id');
    session()->flush();
    if(session()->has('pdt_id'))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}   

My model pop-up which is open on ajax success call

<div id="addmodel" class="modal fade abc123" role="dialog">


             <?php


                        if(session()->has('pdt_id'))
                        {
                            echo  $pdt_id = session()->get('pdt_id');
                        }
                        else
                        {
                                $pdt_id = "";
                        }
                ?>

</div>

but when pop-up open everytime I didn't get diffrent value which store in session though session.can someone help..?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire