Ecshop解决jQuery和toJSONString()的冲突的办法
我做的ecshop模版因为要用到jquery,出现了很多问题,首先就是兼容的问题。
看了很多ecshop怎样解决和jQuery的冲突,好像就一种方法,其本质就都是把transport.js中的toJSONString这个方法替换掉。
我们写系统一般都不会污染全局变量,但是ecshop直接改了系统方法,导致和jquery里面的变量冲突。
那么,我们就的把js中和模板中用到toJSONString方法的地方替换掉。
一、可以自己写一个方法来替换toJSONString这个方法
二、可以用jQuery的插件jQuery-json.js这个插件里面的方法$.toJSON()来替换toJSONString()这个方法
以上两个都要在用到toJSONString方法的模板里面引入这个方法。那么我们来看看那一些文件用到了这个方法呢。
-
\js\common.js:
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}
-
\js\compare.js:
if ( ! Object.prototype.toJSONString) {
Array.prototype.toJSONString = function () {
var a = ['['], // The array holding the text fragments.
b, // A boolean indicating that a comma is required.
-
\js\transport.js:
try
{
legalParams = "JSON=" + params.toJSONString();
}
catch (ex)
-
\themes\default\compare.dwt:
var date = new Date();
date.setTime(date.getTime() + 99999999);
document.setCookie("compareItems", obj.toJSONString());
}
}
-
\themes\default\flow.dwt:
goods.number = number;
goods.parent = 0;
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), collect_to_flow_response, 'POST', 'JSON');
-
\themes\default\library\comments_list.lbi:
Ajax.call('comment.php', 'cmt=' + cmt.toJSONString(), commentResponse, 'POST', 'JSON');
return false;
}
当然,不仅限于我上面写的几处,大家最好还是全局搜索一下,然后改掉所有的比较保险。
ecshop中颜色属性用图片替换颜色的解决方案 ecshop远程商品详情图片本地化保存到本地的方法
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?