{{ $user_count }}
を実際の値(543など)に変換してビューに戻すにはどうすればよいですか?PHP変数をその実際の値に変換するには?
UsersController.php:(私のコントローラが正常にユーザーの数を取得している)
public function userCount(){
$user_count = //Rest of the code to count the row users in the database table
return View::make('data', compact('user_count'); //$user_count holds the number of users
}
====================== ========================================== =
index.blade.php:(私はここにjqueryのを持っている。)
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div id="user_count"></div>
<script>
$(document).ready(function(){
$.ajax({
url: "{{asset('../app/views/data.blade.php')}}",
type: 'GET',
dataType: 'html',
}).done(function(data){
$('#user_count').html(data);
});
});
</script>
============ ========================================== ===========
data.blade.phpは、私がページ/data
ページを試してみました
{{ $user_count }}
、ユーザーの数が表示されます(コントローラからデータを取得します。)しかし、ときに私はAJAXリクエストが出力さプレーンテキストであるにこのようにそれを呼び出す:
{{ $user_count }}