Send data from javascript to controller laravel

I'm getting the error of MethodNotAllowedHttpException when I run the below code:

Temp Form

First Name *
Last Name *
Qualification *
Email address *
Message

Code for routes.php :

Route::post['welcome/addupdate','FormController@addUpdateData'];

code for controller :

 public function addUpdateData[Request $req]
 {
    $id = $req->input['id'];
    if[$id=="add"]
    {
        $bs = new Basicusers;

        $bs->fname = $req->fname;
        $bs->lname = $req->lname;
        $bs->qualification = $req->qualification;
        $bs->email = $req->email;
        $bs->desc = $req->desc;

        $bs->save[];

        return "Data Successfully Added";
    }
  }

What I want is, when user clicks on add button, value in variable data add is passed, and on controller, I will check value for variable and if its add, than I will perform add operation.

meanwhile if the user click on edit button which is provided below in form, that row will be filled in form elements and the add button is changed to update button and value of variable data will be now update and I want to perform update operation...

I'm getting error when I am passing data using POST method moreover I don't know how to get data passed using POST method..

for GET method I am using $id = Input::get['id']; method and its working

Here is JavaScript Function :

function addUpdateData[data] {
  $[function[] {
    $.ajax[{
      method: "post",
      url: "welcome/addupdate",
      data: {
        id: data
      },
      success: function[response] {
        alert[response];
      }
    }];
  }];
}

I need to send data via JS to a Laravel controller on a button click. I'm not using any form because the data is being created dynamically.
Every time i try to send the data, i get an Internal Server Error [500], but unable to catch that exception in the controller or the laravel.log file.

Here's what i'm doing:

Route:

Route::post['section/saveContactItems', 'SectionController@saveContactItems'];

Controller:

public function saveContactItems[$id, $type, $items, $languageID = "PT"]{ ... }

JS:

$['button'].on["click", function [evt] {

    evt.preventDefault[];

    var items = [];
    var id = $["#id"].val[];
    var languageID = $["#languageID"].val[];
    var data = { id: id, type: type, items: JSON.stringify[items], languageID: languageID };

    $.ajax[{
        url: "/section/saveContactItems",
        type: "POST",
        data: data,
        cache: false,
        contentType: 'application/json; charset=utf-8',
        processData: false,
        success: function [response]
        {
            console.log[response];
        }
    }];
}];

What am i doing wrong? How can i accomplish this?

UPDATE: Thanks to @ShaktiPhartiyal's answer [and @Sanchit's help] i was able to solve my issue. In case some else comes into a similar problem, after following @Shakti's answer i wasn't able to access the data in the controller. So, i had to stringify the data before sending it to the server:

data: JSON.stringify[data],

Chủ Đề