lundi 25 décembre 2017

jquery.post() value always gets fail

am new to laravel so please consider that.here when i use jquery.post method i always gets result as fails and i dont know why will it be a problem of route or not here is my code please have a look

<script>
$(".fa-exchange").click(function(){
  var doctor_id=$(this).attr('doctorid');
  $("#doctor_id").val(doctor_id);
  var status=$(this).attr('status');
  $("#status").val(status);
        });
  $("#change-ok").click(function(){

            var doctor_id=$("#doctor_id").val();
            var status=$("#status").val();
            var url='';

            $.post(url, {doctor_id:doctor_id,status:status }).done(function (result) {
               alert("success");
            }).fail(function(result) {
              alert("There was an error. Try again please!");

        });

        });
</script>

My controller looks like this

public function change_doctor_status(Request $request)
{


   $id = $request['doctor_id'];
   $status = $request['status'];
   if($status==1)
   {
      $query=DB::table('doctors')->where('id',$id)->update(['status' => 0]);
      if($query)
      {
        return true;
      }

   }
   else if($status==0)
   {
     $query=DB::table('doctors')->where('id',$id)->update(['status' => 1]);
      if($query)
      {
        return true;
      }
   }
}

i had routed it like this

Route::post('/change-doctor-status', 'Admin\AdminController@change_doctor_status');

here when i go for the result am always getting like this alert("There was an error. Try again please!"); which is stored in the fail section



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

Aucun commentaire:

Enregistrer un commentaire