繁体   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