7
When I use this code in my file, an error occurs in the log, and ends up giving problems in other javascript calls.
Current page file (the problem javascript is at the end):
<html>
<head>
<script src="../../assets/js/common-scripts.js"></script>
<script type="text/javascript">
$(document).ready(
$.ajax('indicadores.php?id_indicador=1').done(function(data) {
$("#collapse1").html(data);
});
);
</script>
</head>
<body>
<section id="container" >
<section id="main-content">
<section class="wrapper">
<div class="row">
<div class="col-lg-12 main-chart">
<h3 class="text-center"><i class="fa fa-bar-chart-o"></i> Indicadores</h3>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1" id="collapse11">Teste</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse active">
<!-- Carrega conteúdo do arquivo pa_nr_atendimentos.php através de Javascript-->
</div>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
</body>
</html>
The last script calls the content that is in the file indicadores.php
:
<!--Com esta chamada apresenta o erro citado. Se eu tirar não apresenta o erro, porém, o conteúdo abaixo sai desconfigurado pela falta do arquivo.-->
<script src="../../assets/js/common-scripts.js"></script>
<div class="panel-body">
<div class="row mt">
<!--AQUI HTML COM GRÁFICOS QUE SE BASEIAM NO ARQUIVO COMMOM-SCRIPTS.JS-->
</div>
</div>
CONSOLE ERROR:
Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience. For more help, check http://xhr.spec.whatwg.org/.
This occurs when I upload the content present on the page indicadores.php
through an asynchronous ajax call, executed on the current page. Does anyone know how to resolve?
Contents of common-scripts.js: http://fiddle.jshell.net/tamh2mo5/:
/*---LEFT BAR ACCORDION----*/
$(function() {
$('#nav-accordion').dcAccordion({
eventType: 'click',
autoClose: true,
saveState: true,
disableLink: true,
speed: 'slow',
showCount: false,
autoExpand: true,
// cookie: 'dcjq-accordion-1',
classExpand: 'dcjq-current-parent'
});
});
var Script = function () {
// sidebar dropdown menu auto scrolling
jQuery('#sidebar .sub-menu > a').click(function () {
var o = ($(this).offset());
diff = 250 - o.top;
if(diff>0)
$("#sidebar").scrollTo("-="+Math.abs(diff),500);
else
$("#sidebar").scrollTo("+="+Math.abs(diff),500);
});
// sidebar toggle
$(function() {
function responsiveView() {
var wSize = $(window).width();
if (wSize <= 768) {
$('#container').addClass('sidebar-close');
$('#sidebar > ul').hide();
}
if (wSize > 768) {
$('#container').removeClass('sidebar-close');
$('#sidebar > ul').show();
}
}
$(window).on('load', responsiveView);
$(window).on('resize', responsiveView);
});
$('.fa-bars').click(function () {
if ($('#sidebar > ul').is(":visible") === true) {
$('#main-content').css({
'margin-left': '0px'
});
$('#sidebar').css({
'margin-left': '-210px'
});
$('#sidebar > ul').hide();
$("#container").addClass("sidebar-closed");
} else {
$('#main-content').css({
'margin-left': '210px'
});
$('#sidebar > ul').show();
$('#sidebar').css({
'margin-left': '0'
});
$("#container").removeClass("sidebar-closed");
}
});
// custom scrollbar
$("#sidebar").niceScroll({styler:"fb",cursorcolor:"#4ECDC4", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled:false, cursorborder: ''});
$("html").niceScroll({styler:"fb",cursorcolor:"#4ECDC4", cursorwidth: '6', cursorborderradius: '10px', background: '#404040', spacebarenabled:false, cursorborder: '', zindex: '1000'});
// widget tools
jQuery('.panel .tools .fa-chevron-down').click(function () {
var el = jQuery(this).parents(".panel").children(".panel-body");
if (jQuery(this).hasClass("fa-chevron-down")) {
jQuery(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
el.slideUp(200);
} else {
jQuery(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
el.slideDown(200);
}
});
jQuery('.panel .tools .fa-times').click(function () {
jQuery(this).parents(".panel").parent().remove();
});
// tool tips
$('.tooltips').tooltip();
// popovers
$('.popovers').popover();
// custom bar chart
if ($(".custom-bar-chart")) {
$(".bar").each(function () {
var i = $(this).find(".value").html();
$(this).find(".value").html("");
$(this).find(".value").animate({
height: i
}, 2000)
})
}
}();
With common-scripts.js in the.php indicators file: No common-scripts.js in.Pho indicators file:
This occurs even though common-scripts.js has already been loaded previously on the current page.
Version of jQuery: 1.8.3
I think it has something to do with this async - true. But I couldn’t fix it. Any hints?
– Rodrigo Segatto
It doesn’t seem that Warning is coming from this question snippet, since jQuery never does synchronous requests by default. This alert is displayed when an Xmlhttprequest request is opened with the parameter
async
as false, example (see the alert on the console).– Guilherme Nagatomo
And how could I solve it? You would know to help me?
– Rodrigo Segatto
The first step would be to identify which script is making the synchronous ajax call
– Guilherme Nagatomo
I can identify it is at the moment it calls 'load' as quoted in the question. Because if I take this code works correctly.
– Rodrigo Segatto
I know the error occurs when the jquery 'load' method occurs
– Rodrigo Segatto
I found this post: http://tedk.com.br/blog/html/carregar-uma-pagina-dentro-de-umadiv-com-ajax/ maybe you have something that can help solve the problem, however, I do not know how to apply in my code
– Rodrigo Segatto
On that page
indicadores.php
does another request (via Ajax)? I’m pretty sure it’s conflicting with another request.– akira-ito
there is an error on the.php indicator page if you leave this request: <script src=".. /.. /Assets/js/common-scripts.js"></script>. If you take this line it works perfectly
– Rodrigo Segatto
The problem is that if I take it out the contents I’m carrying disfigure.
– Rodrigo Segatto
Duplicate question http://answall.com/questions/48011/nos-newbrowsers-agora-n%C3%A3o-haver%C3%A1-mais-requisi%C3%A7%C3%B5es-s%C3%Adncronas
– Wallace Maxters
@Wallacemaxters I don’t think it’s duplicated this one, because the problem is with using Ajax, although both are the same problem, the solution in the question you linked will not help solve the problem that should actually be solved with jQuery (for example using the
$.ajaxSetup
). I believe they are related but not duplicated :)– Guilherme Nascimento
@Wallacemaxters I don’t think so. Your question is about the theoretical aspect, it’s about the prohibition of synchronous AJAX itself. There you are asking if you should change the way of programming, but you have not addressed there how to identify the points that the synchronous AJAX occurs and nor how to eliminate them after identified, which is what occurs in this question here.
– Victor Stafusa
Okay, you guys, let’s go. ;)
– Wallace Maxters
@Rodrigosegatto leaves this inclusion
<script src="../../assets/js/common-scripts.js"></script>
on the page where you load. And removeindicadores.php
– akira-ito
I have it on the page where you load, but after loading the content of.php indicators it’s like it’s gone and I need to load it again there
– Rodrigo Segatto
I don’t quite understand? After all, what do you use this for?
– akira-ito
It’s from the template I downloaded. It makes some graphics work on the screen. On the page where you load has already loaded the JS file, but if I do not also click on indicators.php charts stop working
– Rodrigo Segatto
Test in an older browser. Chrome version 20, IE10, etc. I think jQuery is using some Xmlhttprequest function that is no longer supported. If it functions in an older browser, it must be the cause.
– Thiago Lunardi
In older browser worked. I do not know what can be
– Rodrigo Segatto
I did not understand the reason of the Graphs in relation to doubt, something else your code can not be reproduced, you put the How-js, but did not put the jquery in your html, this gives to understand that this is not your code that is with problem, since if you didn’t include jquery.js the problem would be another in javascript execution.
– Guilherme Nascimento
Dude I have the same problem. Managed to solve ?
– Matheus Miranda