nishanthi nishanthi -3 years ago 173
Ajax Question

How to pass bootstrap modal values to laravel controller using ajax?

I have created a bootstrap modal with some input fields and I am trying to pass those input values to controller and need to insert into db.But it displays null.

It will be helpful if anyone solves my issue.

Answer Source

You just need to change the JS code and laravel redirection with JSON format data like answered by Don't Panic. Added here for other people help so credit goes to him.

JS code:

    var data = $('form').serialize();
        url: 'addPriceDetails/{{$dataId}}',
        type: "post",
        data: data,
        dataType: 'json',
        success: function(response) {

Controller code:

public function addPriceDetails(Request $priceform,$dataId) {
    // ... all your code
    return response()->json([
        'SKUID'    => $priceInfo->SKUID,
        'listingStatus' => $priceInfo->listingStatus
        // ... any other fields you want to return
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download