我想像这样将发件人 id 传递给 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 回答
一只甜甜圈
TA贡献1836条经验 获得超5个赞
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);
},
});
}
添加回答
举报
0/150
提交
取消