作者:爱的记忆2502913597 | 来源:互联网 | 2023-05-17 14:20
Ihavethisweirdissuethatjquery.loadsometimesfailsonchrome.Imnotgonnabotheryouguyswi
I have this weird issue that jquery.load sometimes fails on chrome. I'm not gonna bother you guys with the details, I'm just looking for a pointing hand on how can i debug such an issue?
我有这个奇怪的问题,jquery.load有时会在chrome上失败。我不会打扰你们的细节,我只是想找一个关于如何调试这个问题的指针?
I thought of maybe the firebug could help, but the issue happens only on chrome (even works on IE).
我想也许萤火虫可以提供帮助,但问题只发生在chrome上(甚至适用于IE)。
I do something like:
我做的事情如下:
$("#contentid").html("Plz wait.");
$("#contentid").load(url);
$("#contentid").show();
I get only the "Plz wait" on #contentid, and i can see the url getting called, and check it manually and see it succeeds.
我只在#contentid上获得“Plz等待”,我可以看到url被调用,并手动检查并看到它成功。
UPDATE2:
so i changed the load calls according to suggestions
所以我根据建议更改了加载调用
$('#conentid').load(url, function(response, status, xhr){
alert('Load was performed. url:' + url);
if (status == "error")
{
alert("text: " + xhr.statusText);
alert("readyState: "+xhr.readyState+"\nstatus: " + xhr.status);
alert("responseText: "+xhr.responseText);
}
else
{
$("#conentid").show();
}
});
I get status=='error' when the errors occur.
发生错误时,我得到状态=='错误'。
xhr.statusText: 0
xhr.readyState: 4
xhr.statusText and xhr.responseText are empty
xhr.statusText和xhr.responseText为空
any idea why? what does this mean?
知道为什么吗?这是什么意思?
The url works manually. and this error happens only on chrome, and only sometimes
网址手动工作。并且此错误仅在chrome上发生,有时仅发生
2 个解决方案
4
Chrome actually has rather nice developer tools. Click the wrench icon, select developer tools from the menu.
Chrome实际上有相当不错的开发者工具。单击扳手图标,从菜单中选择开发人员工具。
On this particular issue, I'll bet the show is being called before the load completes -- load happens asynchronously. Set up an event handler for "on load" on #contentid
and do the show in that.
在这个特殊的问题上,我敢打赌在加载完成之前调用show - 异步发生加载。在#contentid上为“on load”设置一个事件处理程序并在其中执行show。
Update
Actually, there's a better way to do it; put your show
into a callback on the load
function:
实际上,有一种更好的方法可以做到这一点;把你的节目放到加载函数的回调中:
$('#conentid').load('ajax/test.html', function() {
alert('Load was performed.');
$('#contentid').show();
});
Another Update
Okay, the ready state of 4 indicates the XmlHTTPRequest completed normally. Now, there's one ambiguity here: is the xhr.statusText 0 or is it empty? What results do you see from this code (including the error code) on another browser?
好的,就绪状态为4表示XmlHTTPRequest正常完成。现在,这里有一个含糊之处:是xhr.statusText 0还是空的?您在其他浏览器上看到此代码(包括错误代码)的结果是什么?
If it's working on firefox, and only working sometimes on Chrome, you may have an actual Chrome bug.
如果它正在使用firefox,并且有时仅在Chrome上运行,那么您可能会遇到实际的Chrome错误。