lundi 31 juillet 2017

Two ajax posts the first one works fine while second one displays parserror

I'm really stuck here , please somebody help: I have two ajax calls with basically identical lines but only one works .

First Ajax post :

$("#languageswitcher").change(function(){


   var locale=$(this).val();
   //alert(111);
   //console.log(111);
  var _token =$("input[name=_token]").val();


   $.ajax({

      url:"/language",
       type:"POST",
       data:{locale:locale,_token:_token},
       dataType:'json',
       success:function(data){

         console.log(data);  
       },
       error: function(ts) {


           //alert(ts.responseText);
       },
       beforeSend:function(){
           console.log(locale);

       },
       complete:function(data){

           window.location.reload(true);

       }
      });

    }) ;

Second one: when i take off dataType:"json" it displays success on alert but send nothing , with the dataType:"json" it displays parserror on alert . i tried with JSON.stringfy() but still displaying the same problem .

$("#change_group").change(function(){

    var group=$(this).val();

    var _token=$("input[name=_token]").val();

    $.ajax({

       url:"/setgroup",
       type:"POST",
        data:{group:group,_token:_token},
        dataType:'json',
       success:function(data,status){
          alert(status);  
        },
       error:function(data,status){
            alert(status);
        },

       beforeSend:function(group){

        },
       complete:function(data){
            window.location.reload();
        }


       });



    });

What can be the issue here? Please somebody help , i'm stuck here for two days now .



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hhVTkO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire