user3550402
user3550402

Reputation: 79

jquery SLOW to call get or post

bit of a heisenbug here...

Have a PHP/codeigniter app here. Pretty sure the controller/model etc. are sound and without bugs. Gotta be a client-side problem...

Very simple code like this in a page:

<div id="stuff">I'm empty now!</div>

<script language="javascript">
$(document).ready(function(){
    var stuffID = <?=$id?>;
    $.post('/event/viewStuff/'+stuffID,
        function(response) {
            $('#stuff').html(response);
        }
    );
});
</script>

After loading the above, the "stuff" div now has a grid of stuff, plus links to page through them 10 at a time, which look like this:

<a href="#" onclick="$('#stuff').html('Wait please...'); $.get('http://localhost/event/viewInvitees/22/30', function(response) {$('#stuff').html(response); }); return false">Next Page</a>

But every time I click these links, the page freezes for 4-5 seconds, doing what I don't know - no network activity, no nothing chrome debugger. Then the "stuff" div reloads with the results. Also - the "Please wait" message is not shown. Weird thing is - when I yank the "document.ready()" function, reload the page, and just click on a bare / hard-coded paging link like the one above, things fires away fast as expected.

Thanks so much for taking time to read.

NEW INFO:

xdebug profile shows nothing unusual - about a 1 second functional call back to the controller/view to return content as expected.

Chrome profiler shows this - a stupid, unexplained idle:

enter image description here


Any additional insight on the "b.event.remove()" jquery function that's taking 6+ seconds? That seems to be the issue?

Upvotes: 2

Views: 2165

Answers (2)

user3550402
user3550402

Reputation: 79

Fixed it - but don't understand the root cause:

As described above - there was a massive delay every time I clicked the "Next Page" link.

Javascript profiling proved that jquery 1.9.1 was hanging for ~6 seconds on b.event.remove(). No idea why. I thought to myself: "Hmm... maybe I've triggered some weirdly inefficient tear-down function. That #stuff div is rather large (lots of sub-forms etc)."

So I tried clearing it out first by adding this command to the link click code:

$('#stuff').html('');

No dice. Then I tried:

$('#stuff').empty();

Same deal - took even longer.

On a lark I then tried the non-jquery method:

document.getElementById('stuff').innerHTML = '';

It worked! The rest of the click-code executed immediately - no more delay!

Question is why??????

Thanks all!

Upvotes: 2

Dwza
Dwza

Reputation: 6565

try to use 127.0.0.1 instead of localhost

in mysql PDO is something like this thats costs performance... so just test it.

Upvotes: 1

Related Questions