Ecshop與Jquery衝突的完美解決方案

來源:互聯網
上載者:User

標籤:使用   turn   jquery衝突   恰恰   comment   this   proc   pretty   port   

ECShop把AJAX事件和JSON解析的模組放在common/transport.js之中,可以說它也有自己封裝的一套工具,這其實是很正常的。

但恰恰的,在封裝JSON各種方法的同時對object的模型進行了重寫,這個就跟jQuery衝突了。因為眾所周知的,jquery對各種JavaScript對象進行了擴充。

這一切其實都很容易理解,各有各的理由十分自然,但頭痛和無奈的就變得在我們這些使用者身上了。在ECShop論壇上原來也有很多朋友提出了這個問題,也提出了各種各樣的方法,我嘗試了一些,不好或者甚至無用,所以只好自己動手了。

解決思路大概就是屏蔽ECshop擴充的toJSONString方法,用別的函數代替。

為了照顧下小菜們,就寫詳細點吧。

1、首先複製一份 transport.js 改名為 transport.org.js 提供給後台使用

2、屏蔽掉transport.js裡的toJSON功能 行數大概有497-737行之間 
由if ( ! Object.prototype.toJSONString) { 開頭的代碼。

修改352行為:

legalParams = “JSON=” + $.toJSON(params);

 

 

修改408行為:

result = $.evalJSON(result);

 

 

屏蔽掉global.js裡的如下代碼(第10-13行):

Object.prototype.extend = function(object) {  return Object.extend.apply(this, [this, object]);}

 

 

3、修改index.js檔案44行改為:

var res = $.evalJSON(result);

 

 

4、修改common.js檔案 
第34行改為:

Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), addToCartResponse, ‘POST’, ‘JSON’);

 

第850行改為:

Ajax.call(‘flow.php?step=add_package_to_cart’, ‘package_info=’ + $.toJSON(package_info), addPackageToCartResponse, ‘POST’, ‘JSON’);

 

第1056行改為:

Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), addToCartResponse, ‘POST’, ‘JSON’);

 

 

5、修改compare.js檔案 
第49行改為:

this.data = $.evalJSON(cookieValue);

 

第67行改為:

var obj = $.evalJSON(cookieValue);

 

第133行改為:

 document.setCookie(“compareItems”, $.toJSON(this.data));

 

6、修改global.js檔案 
第16行改函數名 :function $e() 
第114和126行都改為: var element = $e(element);

7、路徑修改 
修改後台頭部引入transport.js路徑 admin/templates/pageheader.htm 第9行改為:

{insert_scripts files=”../js/transport.org.js,common.js”}

 

admin/templates/menu.htm 
151行改成

{insert_scripts files=”../js/global.js,../js/utils.js,../js/transport.org.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

 

第188行 :

Ajax.call(‘comment.php’, ‘cmt=’ + $.toJSON(cmt), commentResponse, ‘POST’, ‘JSON’);

 

10、compare.dwt 
第20行 :

var obj = $.evalJSON(document.getCookie(“compareItems”));

 

第24行 :

document.setCookie(“compareItems”, $.toJSON(obj));

 

11、flow.dwt 
第138行 :

Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), collect_to_flow_response, ‘POST’, ‘JSON’);

 

第199行 :

Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), fittings_to_flow_response, ‘POST’, ‘JSON’);

12、jquery檔案需置頂的dwt檔案—-jquery.js檔案需要在compare.js檔案載入前載入,否則會報錯

brand.dwtbrand_list.dwtcategory.dwtexchange_list.dwtsearch.dwt

如:

{* 包含指令檔 *}{insert_scripts files=’jquery.js,jquery.json.js’}{insert_scripts files=’common.js,global.js,compare.js’}

Ecshop與Jquery衝突的完美解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.