Appending Laravel Blade from JQuery

后端 未结 2 1194
-上瘾入骨i
-上瘾入骨i 2021-01-27 11:04

I am trying to append Blade syntax from Laravel but can\'t get the browser to understand Blade. When I append the Blade syntax from my js file it output the code onto the page.<

相关标签:
2条回答
  • 2021-01-27 11:30

    Laravel Blade is processing on server side by PHP. Not in your browser like JS. Therefore if you do like you did, you get normal text in your browser. So your server process PHP/Laravel code with Blade and provide for your browser static code with HTML, CSS and JS.

    If it will help you, you can try put your blade code in appropriate *.blade.php file.

    0 讨论(0)
  • 2021-01-27 11:38

    you can generate your view in your controller. and append it to your jQuery

    //blade
    $html = view('someView')->render();
    retrun json_encode($html)
    

    And in your blade you can do something like this

    <script type="text/javascript">
    @if( isset($html) )
     $("#"+Current_box).append({{$html}})
    @endif
    

    I don't know if you are using an ajax call or simply a pageload so dont forget to wrap you script in document ready or ajax function

    0 讨论(0)
提交回复
热议问题