热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用mootools的Ajax请求不起作用-Ajaxrequestusingmootoolsnotworking

Itryloadingcontentintoadivwiththistutorial.Unfortunately,thissimplyloadstheHTMLfile

I try loading content into a div with this tutorial. Unfortunately, this simply loads the HTML file as a new page.

我尝试使用本教程将内容加载到div中。不幸的是,这只是将HTML文件作为新页面加载。

This is the Javascript that should do the job

这是应该完成这项工作的Javascript

window.addEvent('domready', function() {

     $('runAjax').addEvent('click', function(event) {
         event.stop();
         var req = new Request({
             method: 'get',
             url: $('runAjax').get('href'),
             data: { 'do' : '1' },
             onRequest: function() { alert('The request has been made, please wait until it has finished.'); },
              onComplete: function(response) { alert('Response received.); $('container').set('html', response); }
         }).send();
$('runAjax').removeEvent('click');
     });
});

this is the link that should initiate the function

这是应该启动该功能的链接

Profil

and this is the div-structure of index.html. i want the content to be loaded into the "container"-div

这是index.html的div结构。我希望将内容加载到“容器”-div中

content

I dont really care what script i use as long as its compatible with MooTools 1.2, because i need it for a sliding top panel and it would be a lot more work to change it to a jquery panel for example.

我并不关心我使用的脚本,只要它与MooTools 1.2兼容,因为我需要它用于滑动顶部面板,例如将它更改为jquery面板会更多。

3 个解决方案

#1


0  

There is a ' missing here:

这里有一个'失踪:

alert('Response received.);

#2


0  

You're making things more complicated than you need to. Give this a try:

你做的事情比你需要的更复杂。尝试一下:

window.addEvent('domready', function(){
    function loadPage(url) {
        $('container').load(url);
    }

    $('runAjax').addEvent('click', function(e) {
        e.stop();
        loadPage(this.get('href'));
        this.removeEvent('click', loadPage);
    });
});

If that doesn't work, boot up Firebug and see what Javascript errors are getting logged. Here's the reference for the Element.load() shortcut:

如果这不起作用,启动Firebug并查看记录的Javascript错误。这是Element.load()快捷方式的参考:

http://mootools.net/docs/core/Request/Request.HTML#Element:load

http://mootools.net/docs/core/Request/Request.HTML#Element:load

#3


0  

You aren't stopping the click event as recommended.

您没有按照建议停止点击事件。

instead of:

代替:

event.stop();

event.stop();

do:

做:

new Event(event).stop();

new Event(event).stop();


推荐阅读
author-avatar
oth0037112
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有