原型AJAX加载空白页面onSuccess

时间:2013-08-01 06:56:21

标签: javascript ajax prototypejs

我正在研究一个magento项目,而我正试图通过点击更多按钮来加载更多产品。

我可以看到它们正在加载,但之后只会加载一个空白页面。

我不知道发生了什么或为什么。

这是我的代码

    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();
                                }

                            }

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

如果有人能帮助我,那就太棒了!

提前致谢。

2 个答案:

答案 0 :(得分:1)

我在我的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) {

答案 1 :(得分:0)

我可能建议您重写代码并使用 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元素,因此很难给出任何合理的建议。你为调试这个做了什么?

卡尔..