I have an ajax call in $(document).ready function to get a large amount of data and show on page. It returns about 160KB data and takes about 6 seconds. Most of the time it works well but sometimes the error function returns error number 403, 200 or 404 and it doesn’t return data. I really don’t know what’s the problem. here is my ajax code:
jQuery(document).ready(function(){
URL='{% url CompanyHub.views.getServices %}';
jQuery.ajax({
url:URL,
type:'POST',
context: this,
beforeSend:function(xmlHttpRequest){
jQuery('#container').append('<img src="/static/loading.gif" id="loading" />');
},
complete:function(){
jQuery('#loading').remove();
},
success:function(data){
jQuery('#loading').remove();
jQuery('#carousel').html(data);
},
error:function(jqXHR, textStatus, errorThrown){
alert(jqXHR.status);
}
});
});
I didn’t have form element and after sending csrf_token as data in post options the problem was solved: