Tuesday, 15 January 2013

javascript - Jquery variable to php variable in laravel -



javascript - Jquery variable to php variable in laravel -

if (navigator.geolocation) { navigator.geolocation.getcurrentposition(function (position) { $.ajax({ type: "post", url: "/gethamsters", data: { x: position.coords.latitude, y: position.coords.longitude }, success: function (data) { console.log(data); hamsters = data; } }); }); } </script> @foreach ($hamsters $hamster) <div class="col-sm-6 col-md-4 col-lg-3"> <div class="thumbnail"> <center><div>{{ html::image($hamster->foto, $hamster->titel, array( 'width' => 200, 'height' => 200 )) }}</div></center> <div class="caption"> <h3><?php echo substr($hamster->titel, 0, 20); ?></h3> <p><?php echo substr($hamster->beschrijving, 0, 50); ?></p> <center><p><?php echo '<a href=/hamsterdetails/' . $hamster->id . ' class="btn btn-primary" role="button">meer info</a><br /> ';?></p></center> </div> </div> </div> @endforeach

as can see got info jquery result , want pass $hamsters variable in php code. how can that?

since need clearify happening lets step back basics here:

the client requests get /hamsters the server creates , sends response. the client receives response , parses page , runs javascript on (or linked by) document - , can request additional resources ajax. the client posts /gethamsters x, y coordinates via ajax. the server processes post /gethamsters request , returns response client.

javascript php jquery ajax laravel

No comments:

Post a Comment