Archive for the ‘Demos’ Category

Codeigniter的Ajax示例

下载后解压缩到自己的CI目录,导入SQL文件就可以直接查看了。示例是用Google Libraries API的Mootools 1.1.1版本,所以无需再自己下载了。
点击下载示例
示例中的Ajax代码

window.addEvent('domready', function(){
	$$('a[title=status]').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop(); //停止a标签的跳转
			var uri = this.getProperty('href').split("#"); //把URL分割出等下要提交Ajax请求的地址和参数
			var value = uri[1].split("-"); //把参数分割为数据库中的id值和当前status的值
			new Ajax(uri[0], {
				method: 'post', //以post方式提交
				data: Object.toQueryString({
					//生成querystring格式的请求,示例"id=1&status=1"
					id:value[0],
					status: value[1] == '1' ? '0' : '1'
				}),

				//当ajax请求完成时触发的事件
				onComplete: function(vars){
					var r = Json.evaluate(vars); //把从PHP传递过来的Json字符串转换为Javascript对象
					if(r.result){ //判断刚才发送的Ajax请求是否更新成功
						this.setProperty('href', uri[0] + '#' + r.id + '-' + r.status);//更新a标签的URL与参数
						this.setText( r.status );//设置a标签的新文本为更新后的status值
					}
				}.bind(this)
			}).request();
		});

		el.addEvent('mouseover', function(){
			this.setProperty('title', '');
		});
	});
});

Ajax Chart Demo

Powered by WordPress | Shop Free Cellular Phones at Bestincellphones.com. | Thanks to Best CD Rates, iCellPhoneDeals.com Offers Best Cell Phone Deals. and Incinerador De Grasa