简体   繁体   English

原型AJAX在成功上加载空白页

[英]prototype AJAX loading blank page onSuccess

I'm working on a magento project, and I'm trying to load more products on the click of the more button. 我正在做一个magento项目,并且我想通过单击more按钮来加载更多产品。

I can see them loading but then it will just load a blank page after it. 我可以看到它们正在加载,但是之后它只会加载空白页面。

I have no idea what is happening or why. 我不知道发生了什么或为什么。

This is the code I have 这是我的代码

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

                            }

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

If anyone can help me out that would be awesome! 如果有人可以帮助我,那就太好了!

Thanks in advance. 提前致谢。

I've having the same problem in my magento Iphone orginal theme, but the error is because of code injection, mostly "script" tags from google analytics, clicktale and similar stuff. 我的magento Iphone原始主题出现了相同的问题,但是错误是由于代码注入,主要是来自Google Analytics(分析),clicktale和类似内容的“脚本”标签。

what i've done to fix it was to "parse" the ajax response and modify the opening "script" tag with the html entity: 我所做的修复工作是“解析” Ajax响应并使用html实体修改打开的“ script”标签:

below the line 117 (aprox in iphone.js) 第117行以下(iphone.js中为aprox)

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

replace with this: 替换为:

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

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

Might I suggest you rewrite your code and use thiz for that ? 我可能会建议你重写你的代码,并使用THIZ 什么? Your code is extremely hard to read. 您的代码很难阅读。

I do not see any reason to use the onCreate event of the Ajax Request, which by the way is reserved for Ajax Responders (per spec: http://prototypejs.org/doc/latest/ajax/Ajax/Request/ ) 我没有看到使用Ajax请求的onCreate事件的任何理由,顺便说一下,该事件保留给Ajax响应者使用(根据规范: http : //prototypejs.org/doc/latest/ajax/Ajax/Request/

Instead, you can add this classname at the moment you enter into !that.button.hasClassName('loading') ... 相反,您可以在输入!that.button.hasClassName('loading')时添加此类名。

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

There is a lot more going on behind the scene, like your CSS, magento of course, but also containing and parent html elements so it is very difficult to give any sound advice. 幕后还有很多事情要做,比如您的CSS,magento,当然还包含和父html元素,因此很难提出任何合理的建议。 What have you done in order to debug this? 为了调试此功能,您做了什么?

Karl.. 卡尔..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM