ECSHOP_jquery相容方案

來源:互聯網
上載者:User

標籤:style   http   java   color   使用   os   

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

 

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

 

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

 

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

 

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

 

 

一,修改預設js檔案

 

 

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、<!&mdash;&mdash;&mdash;&ndash;路徑修改&mdash;&mdash;&mdash;&ndash;>

修改後台頭部引入transport.js路徑 admin/templates/pageheader.htm 第9行改為: {insert_scripts files=&rdquo;../js/transport.org.js,common.js&rdquo;}

 

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=&rsquo;transport.js,utils.js&rsquo;}上面加上如下代碼

{insert_scripts files=&rsquo;jquery.js,jquery.json.js&rsquo;}

 

 

9、<!&mdash;&ndash;修改檔案&mdash;&ndash;>

library/comment_list.lbi

第188行 :

 

 Ajax.call(&lsquo;comment.php&rsquo;, &lsquo;cmt=&rsquo; + $.toJSON(cmt), commentResponse, &lsquo;POST&rsquo;, &lsquo;JSON&rsquo;);

 

 

10、compare.dwt

第20行 :

 

var obj = $.evalJSON(document.getCookie(&ldquo;compareItems&rdquo;));

 

第24行 :

 

document.setCookie(&ldquo;compareItems&rdquo;, $.toJSON(obj));

 

 

11、flow.dwt

第138行 :

 

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

 

第199行 :

 

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

 

 

12、<!&mdash;&ndash;jquery檔案需置頂的dwt檔案&mdash;-jquery.js檔案需要在compare.js檔案載入前載入,否則會報錯&mdash;&ndash;>

 

brand.dwt

brand_list.dwt

category.dwt

exchange_list.dwt

search.dwt

 

如:

{* 包含指令檔 *}

{insert_scripts files=&rsquo;jquery.js,jquery.json.js&rsquo;}

{insert_scripts files=&rsquo;common.js,global.js,compare.js&rsquo;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.