Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用ajax从控制器调用函数的新路径还是另一种方法?Laravel5.2,Ajax_Php_Jquery_Ajax_Laravel_Session - Fatal编程技术网

Php 使用ajax从控制器调用函数的新路径还是另一种方法?Laravel5.2,Ajax

Php 使用ajax从控制器调用函数的新路径还是另一种方法?Laravel5.2,Ajax,php,jquery,ajax,laravel,session,Php,Jquery,Ajax,Laravel,Session,是否可以在不使用路由的情况下调用控制器中的函数,或者我是否应该使用以下两个参数创建一个新路由,在添加会话后重定向到特定页面 route::get('addsesion/{session name}/{session slug}; 如果可以使用ajax,有人能为我指出正确的方向吗 基本上,我想做的是从一个链接为ajax的控制器调用函数addSession($session\u name,$slug) 我认为您可以在您的视图中使用服务注入绑定控制器功能。 也许你可以参考一下 例如: <html

是否可以在不使用路由的情况下调用控制器中的函数,或者我是否应该使用以下两个参数创建一个新路由,在添加会话后重定向到特定页面

route::get('addsesion/{session name}/{session slug};

如果可以使用ajax,有人能为我指出正确的方向吗

基本上,我想做的是从一个链接为ajax的控制器调用函数
addSession($session\u name,$slug)

我认为您可以在您的视图中使用
服务注入
绑定控制器功能。 也许你可以参考一下

例如:

<html>
@include('head.blade.php')
@inject('currentController', 'App\Http\Controllers\currentController')
</body>
     //on .add-to-partlist click adds session name that is specified in html and the current slug of the page
    <a class="add-to-partlist" href="/seeparts" onClick="{{ $currentController->addSession($session_name, $slug) }}">HERE</a>

</body>
</html>

@包括('head.blade.php')
@注入('currentController','App\Http\Controller\currentController')
//在.add to partlist上,单击添加在html中指定的会话名称和页面的当前slug

我认为使用ajax从方法返回json(ofc您需要路由)是更好的解决方案(更简单)如果ajax调用成功,您可以重定向到另一个页面,如果出现错误,请不要重定向并显示错误,如果我是UAL,我会这样做。因此,我要感谢编辑我的问题以使其更易于理解的人。
<html>
@include('head.blade.php')
</body>
     //on .add-to-partlist click adds session name that is specified in html and the current slug of the page
    <a class="add-to-partlist" href="/seeparts" >Add to partlist</a>

</body>
</html>
<html>
@include('head.blade.php')
@inject('currentController', 'App\Http\Controllers\currentController')
</body>
     //on .add-to-partlist click adds session name that is specified in html and the current slug of the page
    <a class="add-to-partlist" href="/seeparts" onClick="{{ $currentController->addSession($session_name, $slug) }}">HERE</a>

</body>
</html>