如何在响应html代码中显示javascript变量值?
我希望用户在不重新加载页面的情况下进行评论。为此,我通过jquery应用了ajax。当响应到来时,我将html代码附加到刀片中如何在响应html代码中显示javascript变量值?,javascript,jquery,laravel,Javascript,Jquery,Laravel,我希望用户在不重新加载页面的情况下进行评论。为此,我通过jquery应用了ajax。当响应到来时,我将html代码附加到刀片中 success: function(res) { var first_name = res.first_name; var last_name = res.last_name; var profilepic = re
success: function(res)
{
var first_name = res.first_name;
var last_name = res.last_name;
var profilepic = res.profilepic;
var created_at = res.created_at;
$('.profile_comment').prepend(
'<div class="others_comment d-flex mb-15">'+
'<div class="users-img">'+
'<img @if(!empty('+profilepic+')) src="{{URL::asset("uploads/memberprofile/" . '+profilepic+')}}" @else src="{{URL::asset("member/assets/images/user.png")}}" @endif alt="user" class="img-fluid">'+
'</div>'+
'<div class="user_side">'+
'<div class="d-flex">'+
'<h6 class="name">{{ucfirst('+first_name+')}} {{ucfirst('+last_name+')}}</h6>'+
'@php $date= date("F d,Y", strtotime('+created_at+')); @endphp'+
'<p class="ml-auto font-xs">{{$date}}</p>'+
'</div>'+
'<p class="comment">{{ucfirst('+comment+')}}</p>'+
'<div class="footer_comment d-flex">'+
'<button class="btn-none ml-auto"> <img src="{{URL::asset("member/assets/images/option.svg")}}" alt="option" class="img-fluid"> </button>'+
'</div>'+
'</div>'+
'</div>'
);
成功:功能(res)
{
var first_name=res.first_name;
var last_name=res.last_name;
var profilepic=res.profilepic;
var created_at=res.created_at;
$('.profile_comment')。前缀(
''+
''+
''+
''+
''+
''+
{{ucfirst('+first_name+')}{{ucfirst('+last_name+')}+
@php$date=date(“fd,Y”,strotime(“+created_at+”);@endphp”+
“{{$date}
”+
''+
“{{ucfirst('+comment+')}
”+
''+
' '+
''+
''+
''
);
这是我迄今为止尝试过的代码。但它没有显示变量中的值。这是使用Blade和JavaScript时的一个典型问题。Blade的工作方式是查看您的模板,然后将其编译成浏览器可以解释的适当的
.php
文件
这里发生的情况是,在执行任何脚本之前,blade将运行其所有指令。例如,下面一行:
'<img @if(!empty('+profilepic+')) src="{{URL::asset("uploads/memberprofile/" . '+profilepic+')}}" @else src="{{URL::asset("member/assets/images/user.png")}}" @endif alt="user" class="img-fluid">'
使用Blade和JavaScript时,这是一个典型的问题。Blade的工作方式是查看模板,然后将其编译成浏览器可以解释的适当的
.php
文件
这里发生的情况是,在执行任何脚本之前,blade将运行其所有指令。例如,下面一行:
'<img @if(!empty('+profilepic+')) src="{{URL::asset("uploads/memberprofile/" . '+profilepic+')}}" @else src="{{URL::asset("member/assets/images/user.png")}}" @endif alt="user" class="img-fluid">'
你能不能也显示html代码?如果你想快速或更完美地得到答案,请提供更多信息。如果你想快速或更完美地得到答案,请提供更多信息
// server side
return response()->json(['element' => $elementString]);
// client side
$('.profile_comment').prepend(res.element);