为什么jquery设计脚本不适用于ajax脚本返回的产品 [英] Why jquery design script is not working for the products returned by ajax script

查看:104
本文介绍了为什么jquery设计脚本不适用于ajax脚本返回的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了无法解决的问题.部分原因是我无法用正确的术语来解释它.我是新来的,对这个笨拙的问题感到抱歉.

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

下面您可以看到我的目标概述.

Below you can see an overview of my goal.

我正在使用Magento CE 1.7.0.2.

I'm working with Magento CE 1.7.0.2.

在这里您可以看到我的目标.

Here you can see my goal..

对于类别产品,我在JQuery&中编写了一个自定义设计脚本.它运行完美.

for category products i wrote one custom design script in JQuery & its working perfectly.

设计脚本:

<script>
$(document).ready(function(){ 
   $("li.item").each(function(){
      // my design script.
   });
});
</script>

我有一个Ajax脚本,最后我在此页面中显示了一些产品,这个也可以正常工作,但是设计脚本不适用于该产品,而从Ajax脚本获得的所有产品都是如此.

I have one ajax script from that i'm displaying the some of products in this page at last this one also working fine but the script for design is not working for the products what are all the products got from ajax script.

ajax脚本:

$.ajax({
      url: url1,
      cache:  false ,
      type : 'POST',
      // dataType: "json",
      data: data1,
      success: function(response){
        if (response) {
          var string = $('.ajaxproducts', response);
          $('.displayproductsfromajax').html(string);
        }
      }
});

我也想为ajax脚本产品制作相同的设计脚本.

I want make that same design script for ajax script products also.

我在这里做错什么了吗?

Any thing wrong i did here ?

有什么想法吗?

推荐答案

问题是,您仅在dom ready功能上调用了设计脚本.您需要在ajax成功后再次调用它,以应用样式或其他内容.

Problem is, you called the design script only on dom ready function. You need to call it again after ajax succeeded in order to apply the style or something.

function applyScript()
{
 $("li.item").each(function(){
  // my design script.
 });
}

$.ajax({
  url: url1,
  cache:  false ,
  type : 'POST',
  // dataType: "json",
  data: data1,
  success: function(response){
    if (response) {
      var string = $('.ajaxproducts', response);
      $('.displayproductsfromajax').html(string);
      applyScript()
    }
  }
});

这篇关于为什么jquery设计脚本不适用于ajax脚本返回的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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