I have a Laravel app where a blade view which calls a controller backend using Jquery ajaxQ. The blade has an array loop where each element makes the call. I need to queue each element ajax call, i.e. the current ajax call needs to be completed before the next Ajax call is made.
On my route.php, I have this:
$this->group(['middleware' => ['auth', 'profile']], function () {
#get/post here
$this->post('ajaxcall', 'SomeController@ajaxcall');
});
On my view blade, this is how I make my AjAXQ call:
@push('script')
<script src="/js/jquery.ajaxq.js"></script>
<script>
function genopts(){
return {
type: 'POST',
url: '/ajaxcall',
data: data_post,
cache: false,
success: function(){
//some code here
},
error: function(){
//some code
}
dataType: 'json',
async:false
}
}
var csrf_token = $( "input[name*='_token']" ).val();
var arrID = [1, 2, 3, 4, 5];
arrID.forEach(function(id){
var data_post = {};
data_post.id = id;
data_post['_token'] = csrf_token;
$.ajaxq (id, genopts);
});
</script>
@endpush
The AjaxQ returns a 404 error. Previously I was using $.ajax(), but since this is asynchronous, I could not queue each ajax call in its sequential order.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ihvttd
via IFTTT
Aucun commentaire:
Enregistrer un commentaire