简体   繁体   中英

jQuery .ajax XHR request via setInterval doesn't work properly on Raspberry PI Chromium

I'm struggling making the right piece of code with jQuery.

In a nutshell, I want to check if something is completed via XHR request every 1000ms. It does work perfectly on any desktop machine but does n ot work properly on latest raspberry pi with chromium installed.

The client have only one shot on getting HTTP/1.0 200 OK, the thing is the raspberry pi could miss it time to time and it's really annoying.

 var my_interval = null; var k = function() { $.ajax({ url: '/my-ext-request', async: false, type: 'GET', success: function(data) { console.log('Success!!'); clearInterval(my_interval); }, error: function(jHXR, exception, m) { console.error('Error!'); } }); } $(function() { my_interval = setInterval(k, 1000); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

Could anyone propose a better way to do this ? Thank you!

Should not use setInterval, but setTimeout instead.

@Taplar :

Don't do that. async: false not only causes the request to be non asynchronous, which is counter to the paradigm, but also freezes the browser for the duration of the request, which is terrible user experience. Use setTimeout instead. EDIT: Additionally async: false was removed in jquery 3.X

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM