vendredi 9 février 2018

Trying to update the table field with dropdown in laravel?

I am trying to update the table field using dropdown , This is what I tried , but somehow the value doesn't change in the table

this is my controller function

    public function statusChange($oid,$status){
    $order_detail = Order::where('order_id', $oid)->first();
    $order_detail->status=$status;
    $order_detail->save();
    return View::make('view2')->with('name', $status);
}

this is the route:

Route::get('/ajax/{oid}/{status}', 'CustomerController@statusChange');

and this is the view:

 <select id="status" name="class[]">
 @switch ($order->status)
 @case ('received')
 <option selected="received" value="received">received</option>
 <option value="completed">completed</option>
 <option value="cancelled">cancelled</option>
 @break
 @case ('completed')
 <option value="received">received</option>
 <option selected="completed" value="completed">completed</option>
 <option value="cancelled">cancelled</option>
 @break
 @case ('cancelled')
 <option value="received">received</option>
 <option value="completed">completed</option>
 <option selected="cancelled" value="cancelled">cancelled</option>
 @break
 @default
 @break
 @endswitch
 </select>
 @endforeach 

This is the script, once the dropdown changes i can only see alert uid!

 <script type="text/javascript">
 $('select').change( function() {
 var uid= $(this).closest('tr').children('#oid').text();
 //uid="uid="+uid;
 alert(uid);
 //document.cookie = uid;
 var status;
 $(this).find(":selected").each(function () {
 status=( $(this).val() );
 //$('select').val(status);
 //status="status="+status;
 //document.cookie = status;
 //alert(status);
 });
 $.ajax({
 type: "POST",
 url: "/ajax/"$uid+"/"+$status,
 cache: false,
 success: function(result){
 alert(result);
 }
 });


  });
  </script>
 @endsection

Can you please tell me what is that i am doing wrong? p.s: i am new to javascript.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire