var url = '/status_tracker.php';
var params = ['step=2', 'time=1248027314'];
var beacon = new Image();
beacon.src = url + '?' + params.join('&');
beacon.onload = function() {
if (this.width == 1) {
// Success.
} else if (this.width == 2) {
// Failure; create another beacon and try again.
}
};
beacon.onerror = function() {
// Error; wait a bit, then create another beacon and try again.
}
原文出自:《High.Performance.JavaScript》
本文介绍了一种使用JavaScript创建网络请求的方法,通过发送图片请求来模拟HTTP请求,并利用图片加载的状态来判断请求的成功与否。这种方法可以用于监控页面加载情况或者进行简单的网络请求测试。

1026

被折叠的 条评论
为什么被折叠?



