博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_使用MooTools 1.2的基本AJAX请求
阅读量:2514 次
发布时间:2019-05-11

本文共 2954 字,大约阅读时间需要 9 分钟。

mootools

AJAX has become a huge part of the modern web and that wont change in the foreseeable future. MooTools has made AJAX so simple that a rookie developer can get their dynamic pages working in no time.

AJAX已成为现代Web的重要组成部分,并且在可预见的将来不会改变。 MooTools使AJAX变得如此简单,以使新秀开发人员可以立即使用其动态页面。

步骤1:XHTML (Step 1: The XHTML)

Click here to receive a special message from a PHP script via a JavaScript alert.

Click here to populate the element below with the special message.

Special message will appear here.

Here we define two links and a message box. Both links will trigger AJAX calls but there's a difference in how the result is handled. The first will take the response and output the response in a JavaScript alert box. The second link makes an AJAX call but returns the result into the message box.

在这里,我们定义了两个链接和一个消息框。 这两个链接都将触发AJAX调用,但是结果的处理方式有所不同。 第一个将获取响应并将响应输出到JavaScript警报框中。 第二个链接进行AJAX调用,但将结果返回到消息框中。

步骤2:PHP (Step 2: The PHP)

echo 'Hello from PHP!!';

There's very little PHP involved. In this case, we do no "real" programming -- just a simple echo statement.

涉及PHP很少。 在这种情况下,我们不执行“真正的”编程-只是简单的echo语句。

Ste 3:MooTools JavaScript (Ste 3: The MooTools JavaScript)

//on dom ready...window.addEvent('domready', function() {	/* ajax alert */	$('ajax-alert').addEvent('click', function(event) {		//prevent the page from changing		event.stop();		//make the ajax call		var req = new Request({			method: 'get',			url: $('ajax-alert').get('href'),			data: { 'do' : '1' },			onRequest: function() { alert('Request made. Please wait...'); },			onComplete: function(response) { alert('Response: ' + response); }		}).send();	});	/* ajax replace element text */	$('ajax-replace').addEvent('click', function(event) {		//prevent the page from changing		event.stop();		//make the ajax call, replace text		var req = new Request.HTML({			method: 'get',			url: $('ajax-replace').get('href'),			data: { 'do' : '1' },			onRequest: function() { alert('Request made. Please wait...'); },			update: $('message-here'),			onComplete: function(response) { alert('Request completed successfully.'); $('message-here').setStyle('background','#fffea1');			}		}).send();	});});

To create an AJAX request, you must create an instance of the Request class. We provide our request with the method (either get or post), the URL to ping, optional data information, and optional onRequest and onComplete event handlers.

要创建AJAX请求,您必须创建Request类的实例。 我们为请求提供方法( get或post ),ping的URL,可选数据信息以及可选的onRequest和onComplete事件处理程序。

In the first block, we accept the response in the onComplete event handler and alert it out to the screen. The second MooTools block uses the Request.HTML class instead of the Request class. Use the Request.HTML class when you intend to replace a specified element's innerHTML with the AJAX request's response.

在第一个块中,我们在onComplete事件处理程序中接受响应并将其警告到屏幕上。 第二个MooTools块使用Request.HTML类而不是Request类。 当您打算用AJAX请求的响应替换指定元素的innerHTML时,请使用Request.HTML类。

翻译自:

mootools

转载地址:http://oppwd.baihongyu.com/

你可能感兴趣的文章
LVS简略介绍
查看>>
hdu 1021 Fibonacci Again
查看>>
JVM架构_XmnXmsXmxXss有什么区别:转
查看>>
PHPExcel 使用心得
查看>>
洛谷 P3374 【模板】树状数组 1(单点加,区间和)
查看>>
verilog 代码编写小记
查看>>
PyQT的安装和配置
查看>>
从 docker 到 runC
查看>>
守护进程
查看>>
第十二周作业
查看>>
php数组
查看>>
Linux 防火墙
查看>>
互联网金融P2P主业务场景自动化测试
查看>>
array_filter函数的应用
查看>>
梅西确定代言 中国首秀牵手Mate 8
查看>>
html,body
查看>>
一个Brushes笔画应用ios源码完整版
查看>>
IOS 网络浅析-(七 JSON解析之三方JSONKit)
查看>>
image的srcset属性
查看>>
vs + Qt 环境下配置QCustomPlot编译不通过
查看>>