我正在尝试从 Laravel 附加 Blade 语法,但无法让浏览器理解 Blade。当我从 js 文件附加 Blade 语法时,它将代码输出到页面上。
// this is my code..
$("#"+Current_box).append("@if ($errors->has('testing'))<span class='help-block'><strong>{{ $errors->first('testing') }}</strong></span>@endif")
它将输出到页面上:
@if ($errors->has('testing'))
{{ $errors->first('testing') }}
@endif
您可以在控制器中生成视图。并将其附加到您的 jQuery
//blade
$html = view('someView')->render();
retrun json_encode($html)
在你的刀片中你可以做这样的事情
<script type="text/javascript">
@if( isset($html) )
$("#"+Current_box).append({{$html}})
@endif
我不知道您是否正在使用 ajax 调用或只是页面加载,因此不要忘记将脚本包装在文档就绪或 ajax 函数中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)