如何将值从JS函数传递给laravel控制器?

如何将值从JS函数传递给laravel控制器?

问题描述:

我在使用JQ和laravel控制器时遇到麻烦.

I am having trouble with JQ and laravel controller.

这是一个JS文件,需要调用其中包含值的控制器.

As this is a JS file which need to call a controller with a value in it.

function follow_or_unfollow(id,action)
{
    either route call
        myUrl = "{{ route('follows.show','id') }}" ;

    or controller call

 myUrl = "{{ action('FollowsController@show', 'id') }}" ;

bla bla bla !

}

我需要的是:通过在提及"id"的地方打印来发送id的值.目前,它正在打印为id而不是id的值.我已经尝试过类似

What I need is : to send the value of the id by printing there at the place where 'id' is mentioned. at this moment it is printing as id instead of value of the id. I have tried several things like

'+id+'

'"+id+"'

并通过其他变量发送数据.但laravel控制器希望在路由/操作方法中接收数据,而不是从外部接收.任何帮助将不胜感激.预先感谢.

and sending data by other ariable. but laravel controller expect to receive data within the route / action method not from outside. Any help will be apreciated. Thanks in advance.

找到目前可以正常使用的解决方案.谢谢Charletfl!

Find a solution that works fine at this moment. Thanks Charletfl !

是的,链接可以替代执行此工作.像这样:

yes the link can do this job as alternative. like this :

function follow_or_unfollow(id,action)
{
    either route call
        myUrl = "http://foofoo.com/+id" ;

    or controller call

 myUrl = "http://foofoo.com/+id" ;

bla bla bla !

}

通过这种方式,可以将变量值传递给控制器​​,但是仍然提出了一个可研究的问题.就像:如果我们要在php标签内实现/打印一个值,我们应该怎么做..

in this way the variable value can be passed to the controller but still a researchable question is raised. Like : if we want to implement/print a value inside a php tag what should we do ..

感谢帮助朋友!