从JQuery附加Laravel Blade [英] Appending Laravel Blade from JQuery
问题描述
我正在尝试从Laravel追加Blade语法,但无法使浏览器理解Blade.当我从js文件中添加Blade语法时,它将代码输出到页面上.
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.
// 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
推荐答案
Laravel Blade由PHP在服务器端进行处理.不像JS那样在您的浏览器中. 因此,如果您确实喜欢的话,则会在浏览器中看到普通文本. 因此,您的服务器使用Blade处理PHP/Laravel代码,并使用HTML,CSS和JS为浏览器提供静态代码.
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.
如果有帮助,您可以尝试将刀片服务器代码放在适当的 *.blade.php 文件中.
If it will help you, you can try put your blade code in appropriate *.blade.php file.
这篇关于从JQuery附加Laravel Blade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!