How to pass a value from a JS function to a laravel controller?

喜欢而已 提交于 2020-01-16 14:54:13

问题


I am having trouble with JQ and laravel controller.

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 !

}

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+"'

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.


回答1:


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 !

}

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 ..

Thanks for helping friends !



来源:https://stackoverflow.com/questions/20175881/how-to-pass-a-value-from-a-js-function-to-a-laravel-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!