jeudi 10 septembre 2020

how to post checked and unchecked checkbox with onclick ajax laravel

code blade

      <tbody>
    @foreach ($videos as $item)
    <tr>
      <td><img src="" width="100px" height="60px"></td>
      <td></td>
      <td><input type="checkbox" name="status" value="1" onclick="status('slider',  )"
          id="status_slider_"></td>
    </tr>
    @endforeach
  </tbody>

code jquery

function status(id, slider){
$.ajax({
        
        url: "/admin/contents/slider/" + slider,
        type: "post",
        method: "PUT",
        data:{ _token: ""},
        success: function (data) {
            alert('sukses');                     
        },
        error: function (data) {
            console.log(data);
        }
      });
  }

code in controller

public function update(Request $request, $id){
    $videos = Video::find($id);
    $videos['status_slider'] = 1;
    $videos->update();
    return response()->json($videos);
}

I want if someone "ticks" the ajax checkbox send status_slider from that checkbox and {0,1} hangs on if checked then 1, if unchecked 0 to laravel php script by post as soon as it is checked or unchecked,

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire