user8268872
user8268872

Reputation:

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.

Upvotes: 0

Views: 496

Answers (1)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21691

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:

$("#priceSave").click(function(e){
    e.preventDefault();
    var data = $('form').serialize();
    $.ajax({
        url: 'addPriceDetails/{{$dataId}}',
        type: "post",
        data: data,
        dataType: 'json',
        success: function(response) {
            alert(response.SKUID);
        }
    });
});

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
    ]);

Upvotes: 1

Related Questions