2

I'm newbie in ajax and laravel 5

I want pass data with ajax to foreach laravel 5 on the same page.

<div class="row" style="margin:3% 0px 0px 0px">
    @foreach($warung_has_kategoriwarungs['i want pass the data here'] as $Warung)
    <div class="col-md-6" style="margin-bottom:0px;min-height:100px">
        <ul class="no-padding" style="display:inline-flex;list-style-type: none;width:100%;">
            <li>
                <img class="img-circle" src="assets/gambar_contoh/foto.jpg" style="height:60px;width:60px">
            </li>
            <li style="padding:0px 0px 0px 15px ;width:100%">
                <p class="heading-toko-font" style="font-size:18px;color:#606060">{{ $Warung->Warung->nama  }}</p>
                <span class="alamat-toko-font" style="font-size:14px;color:#BCBCBC"><?php echo $Warung['Warung']['alamat']; ?></span>
            </li>
        </ul>

    </div>
    @endforeach
</div>

<div style="text-align:right;">
    {!! $warung_has_kategoriwarungs['and here']->setPath('')->render(); !!}
</div>

and the js here (that i have no idea what i want trying for):

<script>
    $(document).ready(function () {
        $(".kategori-warung").click(function (e) {

            //i want pass this data to foreach parameter

            var txt = $(e.target).text();
            $(".warung").fadeIn("slow").show();
            $("#nama-kategori").html(txt);
            $(".warung-semua").hide();
        });
    });
</script>

1 Answers1

0

I think ajax for the same page call is not the proper solution. I think is better to use helper(Middleware) from laravel 5. This way you can make validations and redirects. Another way it will be to use only javascript to get your data and make the selects. But what are you trying to do is not right. See this post How can I use a JavaScript variable as a PHP variable? Javascript is client side and php is server side you cannot bind them together.

Community
  • 1
  • 1