Как передать переменную из параметра URL-адреса ajax в маршрут laravel? - PullRequest
0 голосов
/ 08 октября 2019

Я хочу передать идентификатор отправителя в маршрут laravel следующим образом, но, похоже, мой код не работает. Пожалуйста, укажите правильный способ сделать это.

url: '/ agent_close / {sender_id}',


function  closeChat(){
  sender = document.getElementById("sender_id").value;
  $.ajax({
           type: "POST",
           url: '/agent_close/{sender_id}',
           data: "sender_id=" + sender, 
           success: function (data) {
                console.log('Message Closed');
                console.log(data);
            },
            error: function (data) {
                console.log('An error occurred');
                console.log(data);
            },
         });
}

Маршрут:

Route::post('/agent_close/{sender_id}', 'AgentController@closeAgentThread');

Функция:

   public function closeAgentThread($sender_id){
        $bot = new BotManController();
        return $bot->TakeThreadControl($sender_id);
    }

Ответы [ 2 ]

2 голосов
/ 08 октября 2019
url: '/agent_close/' + sender,
0 голосов
/ 08 октября 2019
  sender = document.getElementById("sender_id").value;
  $.ajax({
           type: "POST",  //you can use GET instead of POST
           url: '/agent_close/'+sender,   //this line used Route_URL instead Route_name
           data: "",   //can be null
           success: function (data) {
                console.log('Message Closed');
                console.log(data);
            },
            error: function (data) {
                console.log('An error occurred');
                console.log(data);
            },
         });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...