Note that there are some explanatory texts on larger screens.

plurals
  1. POLong polling locking up other AJAX calls
    primarykey
    data
    text
    <p>I'm looking to do long polling to "push" some data down to the client and I'm also making other unrelated AJAX calls to the server in parallel with the long polling. It appears that my other AJAX calls won't complete until the long poll has received a response (either from a response or timeout). When I step through the Javascript, it appears that the 2nd AJAX request is being sent at the proper time, but the response isn't being received until the long poll request gets a response. Any idea what is going on?</p> <p>Here is the code for the long polling portion:</p> <p>Server side:</p> <pre><code> function getPlaylistTracksIfChanged($playlist_id, $numClientTracks) { $reportChange = false; for($i = 0; $i &lt; 10; $i++) { $numServerTracks = $this-&gt;PlaylistTrack-&gt;find('count', array( 'conditions' =&gt; array('playlist_id' =&gt; $playlist_id) ) ); if($numClientTracks != $numServerTracks) { $reportChange = true; break; } sleep(3); } if($reportChange) { $playlist_tracks = $this-&gt;PlaylistTrack-&gt;find('all', array( 'conditions' =&gt; array('playlist_id' =&gt; $playlist_id), 'order' =&gt; array('PlaylistTrack.position') ) ); $this-&gt;set('playlist_tracks', $playlist_tracks); $this-&gt;layout = false; $this-&gt;render('show_playlist_tracks_list'); } else { $this-&gt;autoRender = false; return 'false'; } } </code></pre> <p>Client side:</p> <pre><code>function checkForChangesOnServer() { $.post('/getResultsIfChanged/' + playlist_id + '/' + $('#sortable_tracks').children().size(), function(results) { if(results == 'false') { //alert('no change'); } else { //alert('change'); } checkForPlaylistChangesOnServer(); }); } </code></pre> <p>And a sample of another AJAX call:</p> <p>Server side:</p> <pre><code> function getLibraryTracksStartingWithLetter($user_id, $letter) { $results = $this-&gt;Track-&gt;find( 'all', array( 'conditions' =&gt; array( 'user_id' =&gt; $user_id, 'OR' =&gt; array( 'Track.artist LIKE' =&gt; $letter . '%', 'Track.name LIKE' =&gt; $letter . '%' ) ), 'order' =&gt; array('case when Track.artist = "" then 1 else 0 end', 'Track.artist', 'Track.name') ) ); $this-&gt;set('results', $results); $this-&gt;layout = false; $this-&gt;render('show_library_results_list'); } </code></pre> <p>Client side:</p> <pre><code> function loadLibraryResultsForLetter(letter) { highlightLetterFilter(letter); $.post('/getLibraryTracksStartingWithLetter/' + user_id + '/' + letter, function(results) { updateLibraryResults(results); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload