javascript - AJAX fire-and-forget, looking for the opposit of Server-sent event - Stack Overflow
Using XMLHttpRequest to send an async request (i.e. where you don't care if it succeeds or what the response is:
var req = new XMLHttpRequest(); req.open('GET', 'http://my.url.goes.here.com'); req.send();
You can do much the same thing with an Image object, too, btw:
new Image().src = 'http://my.url.goes.here.com';
The Image approach works particularly well if you're making cross-domain requests, since Images aren't subject to same-origin security restrictions the way XHR requests are. (BTW, it's good practice but not essential to have your endpoint return a 1x1 pixel PNG or GIF response with the appropriate Content-Type, to avoid browser console warnings like 'Resource interpreted as Image but transferred with MIME type text/html'.)
Read full article from javascript - AJAX fire-and-forget, looking for the opposit of Server-sent event - Stack Overflow
No comments:
Post a Comment