0

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.

4
  • Ok, provide your model code with route too Commented Aug 17, 2017 at 8:33
  • Provide your html, js, controller code to Commented Aug 17, 2017 at 8:34
  • stackoverflow.com/questions/45727405/… Commented Aug 17, 2017 at 8:39
  • There includes all my code Commented Aug 17, 2017 at 8:39

1 Answer 1

1

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
    ]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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