现在的位置: 首页 > 综合 > 正文

Chrome浏览器未受理ajax请求

2018年05月24日 ⁄ 综合 ⁄ 共 773字 ⁄ 字号 评论关闭

    问题描述如下:一个A标签,点击的时候执行两个操作,下载一个资源并且同时发出ajax请求。在Chrome浏览器下,ajax请求被cancel掉了,但是firefox很正常。

代码如下:

<td><a href="$!dotNetClient.outLink" onclick="insertDownloadLog(4)"><span style="color:blue;">下载</span></a></td>


function insertDownloadLog(fileType){
	$.ajax({
		url:"/download/insertDownloadLog.action?rand=" + new Date().getTime(),
		type:'GET',
		data:{
			'fileType' : fileType
		},error:function(){
			return false;
		},success:function(){
			return true;
		}
	});
}

debugChrome的信息:


用firefox没有问题。


通过延迟发送请求可以解决这个问题。解决代码如下:

function insertDownloadLog(fileType,outlink){
	setTimeout(function(){
			$.ajax({
				url:"/download/insertDownloadLog.action?rand=" + new Date().getTime(),
				type:"POST",
				data:{
					'fileType' : fileType
				},error:function(){
					return false;
				},success:function(){
					return true;
				}
			});
	}, 3000);
}


以我现在的Js眼界来看,这是Chrome的一个bug,不知道到大家对这个问题的看法如何。欢迎跟帖评论。




抱歉!评论已关闭.