0

I am new to laravel. I am trying to send javascript data to controller. In my view I have listed records using bootstrap table. When the user check the table row checkbox I want it's id to get store in the a variable and when the user click the add button it should send the id to the controller html code

<div class="col-md-12" >

                             <table class="table table-hover"  data-toggle="table"  id="table"
                             data-click-to-select="true">
                                <thead>
                                  <tr>
                                    <th data-field="state" data-checkbox="true" ></th>

                                    <th data-field="roomname">Room Name</th>
                                    <th data-field="Desc">Description</th>
                                    <th data-field="price">Price</th>
                                    <th data-field="roomid" data-visible="false">Price</th>
                                  </tr>
                                </thead>
                                <tbody >
                                  @foreach($roomname as $value)
                                  <tr>

                                    <td>{!! $value->roomid !!}</td>
                                    <td>{!! $value->roomname !!}</td>
                                    <td>{!! $value->Desc !!}</td>
                                    <td>{!! $value->price !!}</td>
                                    <td >{!! $value->roomid !!}</td>
                                  </tr>
                                  @endforeach
                                </tbody>
                              </table>



                    </div>
                    <div class="col-md-12">
                      <br>

                      <button id="add_cart" class="btn btn-warning">Proceed to booking</button>

</div>
2
  • Did you try with ajax? Commented Jun 20, 2016 at 10:28
  • i used ajax but it throws error 505 Commented Jun 21, 2016 at 8:06

1 Answer 1

1

you can solve it without javascript if you make a route for it..

@foreach($roomname as $value)
    <tr>
        <td>{!! $value->roomid !!}</td>
        <td>{!! $value->roomname !!}</td>
        <td>{!! $value->Desc !!}</td>
        <td>{!! $value->price !!}</td>
        <td >{!! $value->roomid !!}</td>
        <td><a href={!! route('routeName', ['id' => $value->roomid]) !!}
    </tr>
@endforeach

if you want to submit multiple id's to the controller for editing/booking that you can solve by a form or via ajax.

Sign up to request clarification or add additional context in comments.

3 Comments

here is my ajax code not working $("#add_cart").click(function() { $("#output").empty(); $.each(checkedRows, function(index, value) { data+= value.id + ','; $.ajax({ url: 'booking/SelectedTableId', type: "post", data: {dataval:data}, success: function(data){ alert(data); } }); }); });
plz nebody help me
@MassumHussain please dit your question to add ajax and your routes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.