简体   繁体   English

在jQuery中从外部文件加载数据

[英]Loading Data From External File in Jquery

I am probably missing something minuscule here, but I'm sure an extra set of eyes (or someone more expeireinced with JQuery) will be the answer to this. 我可能在这里错过了一些微不足道的东西,但是我敢肯定,另外一双眼睛(或者更熟悉JQuery的人)将是解决方案。

Our shopping cart is hosted by BigCommerce, and sometimes we need to come up with work arounds in order for things that should be standard out of the box, implemented. 我们的购物车由BigCommerce托管,有时我们需要提出解决办法,以实现应开箱即用的标准功能。 So on our category pages (example here: http://www.contourliving.com/pillows/ ), the little short descriptions that are loaded into every listing are called by using a jquery script similar to this: 因此,在我们的类别页面(此处为示例: http : //www.contourliving.com/pillows/ )上,使用类似于以下内容的jquery脚本调用了加载到每个列表中的简短描述:

$("#this_div_is_called_on_cat_page).load("path_to_external_file #div");

And if you look at the category page, it seems to work, however there are the occasional products that are not working as expected. 而且,如果您查看类别页面,它似乎可以正常工作,但是偶尔会有一些产品无法正常工作。 Even though the divs in are external file, they are just not getting loaded. 即使div是外部文件,它们也不会被加载。

So my question to this mystery is, why would this be occurring? 所以我对这个谜题的疑问是,为什么会这样呢? What am I missing here? 我在这里想念什么? Listed below is a link to my external file (as Im thinking that is where it has to be going wrong); 下面列出的是我的外部文件的链接(因为我认为这是必须要出问题的地方);

http://deals.contourliving.com/template/Snippets/CategoryProductSummary.html http://deals.contourliving.com/template/Snippets/CategoryProductSummary.html

Thanks in advance, Kate 预先感谢凯特

Try adding a callback function to your load() calls, then use your web browser's Javascript console to inspect the results. 尝试在您的load()调用中添加一个回调函数,然后使用Web浏览器的Javascript控制台检查结果。 This should help you understand what's going wrong. 这应该可以帮助您了解问题所在。 Here's an example: 这是一个例子:

$("#prod_summary_377").load("http://your-website.com/template/Snippets/CategoryProductSummary.html #377", function(response, status, xhr){
  console.log(status);
  if (status == "error") {
    console.log(xhr.status + " " + xhr.statusText);
  }
});

See the jQuery documentation for more information. 有关更多信息,请参见jQuery文档

Also, your CategoryProductSummary.html page contains 2 div elements with the same ID: <div id="337"> , so try fixing that. 另外,您的CategoryProductSummary.html页面包含2个具有相同ID的div元素: <div id="337"> ,因此请尝试对其进行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM