为什么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 ?
我遇到了无法解决的问题。 部分是因为我无法用正确的术语来解释它。 对于这个笨拙的问题,我很陌生。 p>
下面你可以看到我的目标概述。 p>
我正在努力 Magento CE 1.7.0.2。 p>
在这里你可以看到我的目标... p>
我在JQuery&amp; amp;中编写了一个自定义设计脚本的类别产品。 它的工作正常。 p>
设计脚本 strong>: p>
我有一个ajax脚本,我正在显示这个页面中的一些产品,最后这个也工作正常,但设计脚本不适用于产品 什么是从ajax脚本获得的所有产品。 p>
ajax脚本 strong>: p>
我想为ajax脚本产品制作相同的设计脚本。 p>
我在这里做错了什么? p>
有什么想法吗? p>
&lt; script&gt;
$(document)。 ready(function(){
$(“li.item”)。each(function(){
// my design script。
});
});
&lt; / script&gt;
pre>
$ .ajax({
url:url1,
cache:false,
type:'POST',
// dataType:“json”,
data:data1,
success:function(response){
if(response) ){
var string = $('。ajaxproducts',response);
$('。displayproductsfromajax')。html(string);
}
}
});
code>
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()
}
}
});
You have to be able to call your design algo on seperate collection so wrap it inside a function like this
var myDesign = function(i,el){
// this will be a reference to the current li.item in "each"
};
$(document).ready(function(){
$("li.item").each(myDesign);
});
...
$.ajax({
url: url1,
cache: false ,
type : 'POST',
// dataType: "json",
data: data1,
success: function(response){
if (response) {
var string = $('.ajaxproducts', response);
$('.displayproductsfromajax').html(string).find('li.item').each(myDesign);
}
}
});