jQuery的XMLHtt prequest错误 [英] jQuery XMLHttpRequest error

查看:141
本文介绍了jQuery的XMLHtt prequest错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有jQuery中未定义的错误,由于Ajax请求。但是,它的工作原理在本地。错误引用的jquery1.3.2.js @ 3633行

There is an undefined error due Ajax request in jQuery. But it works locally. Error referencing in jquery1.3.2.js @ 3633 line

    xhr.send(s.data);

我的code是:

My code is:

    $.ajax({
	type: "POST",
	url: 'index.php',
	data: "action=showpath&type=images&path=&default=1",
	cache: false,
	dataType: "html",
	success: function(data){
		$('#addr').html(data);
	},
    error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(thrownError);
    }       
});

在code警报显示我的(0,未定义);

alerts in code shows me (0, 'undefined');

我在做什么错了?

推荐答案

这可能会发生,如果你的Ajax请求在完成前得到取消。 jQuery的引发错误事件在用户离开页面或者通过令人耳目一新,点击一个链接,或改变浏览器的URL。您可以通过检测这些类型的错误通过实现Ajax调用错误处理程序,并检查xmlHtt prequest对象:

This could be happening if your ajax request is getting canceled before it completes. jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. You can detect these types of errors by by implementing an error handler for the ajax call, and inspecting the xmlHttpRequest object:

$.ajax({
    /* ajax options omitted */
    error: function (xmlHttpRequest, textStatus, errorThrown) {
         if(xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0) 
              return;  // it's not really an error
         else
              // Do normal error handling
});

这篇关于jQuery的XMLHtt prequest错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆