weixin_33720452 2018-12-01 14:15 采纳率: 0%
浏览 61

Laravel Route jQuery

I'm using Ajax to get and display content in a Laravel view. I'd like to know how I can access the second parameter in the URL. It's currently giving me back a random string:

for(var i=0;i<array.length;i++){
    html+="<a href={{ route('showAnnouncement',"array[i].id_announcement") }}>";
}

When I alert array{i].id_announcement I get its value, but it doesn't pass in the URL.

Thank you!

  • 写回答

2条回答 默认 最新

  • weixin_33726313 2018-12-01 17:07
    关注

    You can't access a JS value inside a php code.

    {{route('showAnnouncement',"array[i].id_announcement") }}

    This not possible, If you are making ajax request you try something like this below.

    var an_id = array[i].id_announcement;
    
    $.ajax({
        url: '{{route('showAnnouncement')}}',
        data: {'an_id':an_id },
        type: 'POST',
        success: function (result)
        {
        }
     });
    

    Route

    Route::post('showAnnouncement/{an_id?}', ['as' => 'showAnnouncement', 'uses' => 'YourController@showAnnouncement']);
    
    评论

报告相同问题?