I'm developing a Laravel project and I'm facing an issue with Ajax and Blade template. In my scenario I have several tag (it can be divs, buttons or list items) with a class ajaxaction and an attribute data-route, like this:
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5106">
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5105">
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5104">
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5103">
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5102">
and a tag wrapping the content i will replace:
<div class="content">
</div>
In this page I have the script like this:
$('.ajaxaction').click(function () {
ajaxURL = $(this).attr('data-route');
$.get( ajaxURL, function(data) {
$('.content').html(data);
})
.fail( function(jqXHR, textStatus, errorThrown) {
$('.content').html(textStatus + ' ' + errorThrown);
});
});
As I expect every time a tag is clicked the ajax send a GET request that return an HTML that replace the previous in content. In some case the content replaced has a tag with class ajaxaction itself like this:
<div class="content">
...
<button type="button" class="ajaxaction" data-route="http://localhost/webora/public/d/5199">
...
</div>
But clicking on this tag do not send any ajax request.