仅在使用 Chrome 时出现 jQuery load 和 getJSON 问题
我遇到了两个 jQuery 调用的问题。第一个是“加载”,它检索 HTML 并将其显示在页面上(它在返回的代码中包含一些 Javascript 和 CSS)。第二个是返回 JSON 的“getJSON” - 返回的 JSON 是有效的。
在我尝试过的所有其他浏览器中一切都工作正常 - 除了适用于 Windows 或 Mac 的 Chrome 浏览器。有问题的页面在这里:
http://urbanistguide.com/category/Contemporary.aspx
当您在 IE/FF 中单击餐厅名称时,您应该会看到该项目展开并显示更多信息 - 并在右侧显示地图。但是,如果您在 Chrome 中执行此操作,您得到的只是打印到屏幕上的 JSON 数据。
第一个问题是当这里调用“load”函数时:
var fulllisting = top.find(".listingfull");
fulllisting.load(href2, function() {
fulllisting.append("<div style=\"width:99%;margin-top:10px;text-align:right;\"><a href=\"#\" class=\"" + obj.attr("id") + "\">X</a>");
itemId = fulllisting.find("a.listinglink").attr("id");
...
在上面的代码中,回调函数似乎没有被调用。
第二个问题是当调用“getJSON”函数时:
$.getJSON(href, function(data) {
if (data.error.length > 0) {
//display error message
}
else {
...
}
在这种情况下 - 它似乎只是跟随链接而不是执行回调......是的,我正在执行“return false;”在所有这一切结束时以防止链接执行。
如果您想查看源代码,则所有其余代码都内联在该页面上。
有什么想法吗?
谢谢
I'm having an issue with two jQuery calls. The first is a "load" that retrieves HTML and displays it on the page (it does include some Javascript and CSS in the code that is returned). The second is a "getJSON" that returns JSON - the JSON returned is valid.
Everything works fine in every other browser I've tried - except Chrome for either Windows or Mac. The page in question is here:
http://urbanistguide.com/category/Contemporary.aspx
When you click on a Restaurant name in IE/FF, you should see that item expand with more info - and a map displayed to the right. However, if you do this in Chrome all you get is the JSON data printed to the screen.
The first problem spot is when the "load" function is called here:
var fulllisting = top.find(".listingfull");
fulllisting.load(href2, function() {
fulllisting.append("<div style=\"width:99%;margin-top:10px;text-align:right;\"><a href=\"#\" class=\"" + obj.attr("id") + "\">X</a>");
itemId = fulllisting.find("a.listinglink").attr("id");
...
In the above code, the callback function doesn't seem to get invoked.
The second problem spot is when the "getJSON" function is called:
$.getJSON(href, function(data) {
if (data.error.length > 0) {
//display error message
}
else {
...
}
In this case - it just seems to follow the link instead of performing the callback... and yes, I am doing a "return false;" at the end of all of this to prevent the link from executing.
All of the rest of the code is inline on that page if you want to view the source code.
Any ideas??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
loadBusiness(obj, doScrollTo)
中,将top = obj.parent().parent().parent()
重新声明为var top = obj.parent()。父().父()
。现在的方式是指 window.top 中的全局变量
top
。由于它是一个特殊变量,Chrome 不允许您重新定义它。当您运行var fulllisting = top.find(".listingfull")
时,您实际上是在运行var fulllisting = window.find(".listingfull")
(检查 https://developer.mozilla.org/en/DOM/window.find)。此方法返回 false,然后在此处引发异常:fulllisting.load(...)
,因为它与false.load(...)
相同In
loadBusiness(obj, doScrollTo)
redeclaretop = obj.parent().parent().parent()
asvar top = obj.parent().parent().parent()
.The way you have it now it refers to the global variable
top
as in window. Because it is a special variable, Chrome doesn't allow you to redefine it. When you runvar fulllisting = top.find(".listingfull")
you are essentially runningvar fulllisting = window.find(".listingfull")
(check https://developer.mozilla.org/en/DOM/window.find). This method returns false and then an exception is thrown here:fulllisting.load(...)
because it is the same asfalse.load(...)
Chrome 过于严格,无法识别格式错误的 JSON 对象,这与其他浏览器不同。
你必须将其更改为
or
,当然省略最后一个。
Chrome is too strict and doesn't recognize malformed JSON object, not like other browsers.
you have to change it to
or
and of course omit the last one.