dongxianchu3541 2014-04-09 11:41
浏览 46
已采纳

为什么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.

I'm working with Magento CE 1.7.0.2.

Here you can see my goal..

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

Design Script :

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

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 script :

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

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

Any thing wrong i did here ?

Any ideas ?

  • 写回答

2条回答 默认 最新

  • douzi1991 2014-04-09 11:44
    关注

    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()
        }
      }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP