完美解决ecshop与jquery冲突兼容

示例:http://www.yunweii.com/


原因分析:
     在transport.js文件中,大概 580行到590行之间,这个句用于格式化json,他重写了object的结构,导致于js框架冲突。冲突的原因是jquery给一个object增加了很多元素,那么在Object.prototype.toJSONString = function () 这个函数中 for (k in this) 语句中进行了无数次的循环,导致网页很卡,并且在IE中会报错。

ecshop2.7.2/2.7.3解决jquery的冲突,亲测,无误
 
1.先复制一份 transport.js 改名为 transport.org.js 提供给后台调用
 
2.注释掉js/transport.js里的toJSON功能 行数为497-737行之间。其中将
 
legalParams = "JSON=" + params.toJSONString();
 
替换为
 
legalParams = $.evalJSON(params);
 
然后把
 
result = result.parseJSON();
 
修改为
 
result = $.evalJSON(result);
 
3.修改js/index.js里的第44行,将
 
var res = result.parseJSON();
 
改为:
 
var res = $.evalJSON(result);
 
4.修改js/改common.js,
 
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
 
修改为
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), addToCartResponse, 'POST', 'JSON');
 
然后把
 
Ajax.call('flow.php?step=add_package_to_cart', 'package_info=' + package_info.toJSONString(), addPackageToCartResponse, 'POST', 'JSON');
 
修改为
 
Ajax.call('flow.php?step=add_package_to_cart', 'package_info=' + $.toJSON(package_info), addPackageToCartResponse, 'POST', 'JSON');
 
最后把
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
 
修改为
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), addToCartResponse, 'POST', 'JSON');
 
5.修改compare.js文件
 
 
this.data = cookieValue.parseJSON();
 
修改为
 
this.data = $.evalJSON(cookieValue);
 
然后把
 
var obj = cookieValue.parseJSON();
 
修改为
 
var obj = $.evalJSON(cookieValue);
 
最后把
 
document.setCookie("compareItems", this.data.toJSONString());
 
修改为
 
document.setCookie("compareItems", $.toJSON(this.data));
 
6.修改js/global.js文件
 
 
function $()
 
修改为
 
function $e()
 
然后把
 
var element = $(element);
 
修改为
 
var element = $e(element);
 
7.修改后台头部引入transport.js路径 admin/templates/pageheader.htm 第9行改为:
 
{insert_scripts files="../js/transport.org.js,common.js"}
 
8.修改themes/default/library/page_header.lbi文件在
 
{insert_scripts files='transport.js,utils.js'}
 
上面加上如下代码
 
{insert_scripts files='jquery.js,jquery.json.js'}
 
9.修改你的模板下的library/comment_list.lbi。
 
 
Ajax.call('comment.php', 'cmt=' + cmt.toJSONString(), commentResponse, 'POST', 'JSON');
 
修改为
 
Ajax.call('comment.php', 'cmt=' + $.toJSON(cmt), commentResponse, 'POST', 'JSON');
 
10.修改模板compare.dwt。
 
 
var obj = document.getCookie("compareItems").parseJSON();
 
修改为
 
var obj = $.evalJSON(document.getCookie("compareItems"));
 
然后把
 
document.setCookie("compareItems", obj.toJSONString());
 
修改为
 
document.setCookie("compareItems", $.toJSON(obj));
 
11.修改模板flow.dwt
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), collect_to_flow_response, 'POST', 'JSON');
 
修改为
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), collect_to_flow_response, 'POST', 'JSON');
 
然后把
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), fittings_to_flow_response, 'POST', 'JSON');
 
修改为
 
Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), fittings_to_flow_response, 'POST', 'JSON');
 
12.这样就可以了,若果需要使用ajax那么请用修改后的json功能。
 
相关文件
 
jquery.json-1.3.js  下载链接里边也含有。
 
posted @ 2014-11-25 10:40  江哥哥  阅读(536)  评论(0编辑  收藏  举报