簡體   English   中英

原型AJAX在成功上加載空白頁

[英]prototype AJAX loading blank page onSuccess

我正在做一個magento項目,並且我想通過單擊more按鈕來加載更多產品。

我可以看到它們正在加載,但是之后它只會加載空白頁面。

我不知道發生了什么或為什么。

這是我的代碼

    var loadMore = Class.create({
        initialize: function (list, href, pattern) {
            var that = this;

            this.list = list;
            this.list.insert({ after : '<div class="more"><span id="more_button" class="more-button">More</span></div>'});
            this.href = href.readAttribute('href');
            this.button = $('more_button');
            this.holder = new Element('div', { 'class': 'response-holder' });

            this.button.observe('click', function () {
                if ( !that.button.hasClassName('loading') ) {
                    new Ajax.Request(that.href, {
                        onCreate: function () {
                            that.button.addClassName('loading');
                        },
                        onSuccess: function(response) {
                            if (200 == response.status) {
                                   that.holder.update(response.responseText).select(pattern).each(function(elem) {
                                   that.list.insert({ bottom : elem });

                                }),



  that.href = that.holder.select('.next-page')[0].readAttribute('href');
                                that.button.removeClassName('loading');

                                if ( !that.href ) {
                                    that.button.up().remove();
                                }

                            }

                        }
                    });
                }
            });
        }
    });

如果有人可以幫助我,那就太好了!

提前致謝。

我的magento Iphone原始主題出現了相同的問題,但是錯誤是由於代碼注入,主要是來自Google Analytics(分析),clicktale和類似內容的“腳本”標簽。

我所做的修復工作是“解析” Ajax響應並使用html實體修改打開的“ script”標簽:

第117行以下(iphone.js中為aprox)

if (200 == response.status) {
that.holder.update(response.responseText).select(pattern).each(function(elem) {

替換為:

str = response.responseText;                                
str  = str.replace(/<script/gi, '&lt;script');

that.holder.update(str).select(pattern).each(function(elem) {

我可能會建議你重寫你的代碼,並使用THIZ 什么? 您的代碼很難閱讀。

我沒有看到使用Ajax請求的onCreate事件的任何理由,順便說一下,該事件保留給Ajax響應者使用(根據規范: http : //prototypejs.org/doc/latest/ajax/Ajax/Request/

相反,您可以在輸入!that.button.hasClassName('loading')時添加此類名。

if ( !that.button.hasClassName('loading') ) {
    that.button.addClassName('loading');
    new Ajax.Request(that.href, {
....

幕后還有很多事情要做,比如您的CSS,magento,當然還包含和父html元素,因此很難提出任何合理的建議。 為了調試此功能,您做了什么?

卡爾..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM