ThinkAjax的用法解析及实例
来源:互联网 发布:淘宝无线链接转换 编辑:程序博客网 时间:2024/05/17 01:55
重点函数1:
$this->ajaxReturn($result,"型号增加成功!",1);
第一个是返回的数据变量,第二个是返回的信息,第三个是数据返回的状态。
重点函数2:
ThinkAjax.send('__APP__/Index/delete/','ajax=1&partid='+partid,delComplete,'result');
第一个参数:在控制器里面的函数名称
第二个参数:需要传递的参数ajax=1好像不可少
第三个参数:提交成功执行的函数名称
第四个参数,就是显示“数据处理中~”这些提示信息的Div的名称。
重点函数3:
ThinkAjax.sendForm('frmpart','__APP__/Index/insert',addComplete,'result');
第一个参数代表提交名称为frmpart的表单
第二是参数是提交的地址
第三个参数,如果提交成功,执行的函数名称
第四个参数,就是显示“数据处理中~”这些提示信息的Div的名称。
<div id="result" class="none result" style="float:right;font-family:微软雅黑,Tahoma;width:150px;letter-spacing:2px"></div>
function addComplete(data,status)
其中的data参数,就是我们提交成功之后的返回值
$this->ajaxReturn($result,"型号增加成功!",1);
那么,data就是变量$result的值,sataus就是最后的这个参数"1"或者"0"
当然,别忘了在用ThinkAJAX的时候写上
XML/HTML代码
<load href="__PUBLIC__/Js/Base.js" />
<load href="__PUBLIC__/Js/prototype.js" />
<load href="__PUBLIC__/Js/mootools.js" />
<load href="__PUBLIC__/Js/Ajax/ThinkAjax.js" />
下面是代码
先看模板文件代码(着重看红色部分代码):
<tagLib name="html" />
<include file="Public:header" />
<SCRIPT LANGUAGE="JavaScript">
<!--
function addStock(){
ThinkAjax.sendForm('frmpart','__APP__/Index/insert',addComplete);
}
function addComplete(data,status){
if (status==1)
{
window.setTimeout(function (){window.location.href='__URL__',20000});
}
}
function delStock(partid){
ThinkAjax.send('__APP__/Index/delete/','ajax=1&partid='+partid,delComplete);
}
function delComplete(data,status){
if (status==1)
{
window.setTimeout(function (){window.location.href='__URL__',20000});
}
}
//-->
</SCRIPT>
<table width="80%" border="1" cellspacing="0" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<!--数据新增表单-->
<form name=frmpart>
<tr bgcolor='#E8E8E8'>
<td width="10%"><input type="hidden" name="ajax" value="1"><input type="button" value="新增数据" onclick="addStock()"></td>
<td width="38%">型号:<input type="text" id="partno" name="partno">
<div id="result" class="none result" style="float:right;font-family:微软雅黑,Tahoma;width:150px;letter-spacing:2px"></div>
</td>
<td width="25%">厂家:<input type="text" id="mfg" name="mfg"></td>
<td width="12%">批号:<input type="text" id="datecode" name="datecode"></td>
<td width="15%">数量:<input type="text" id="qty" name="qty"></td>
</tr>
</form>
<tr bgcolor='#E8E8E8'>
<td width="10%"><strong>ID</strong></td>
<td width="38%"><strong>PartNo.</strong></td>
<td width="25%"><strong>Mfg.</strong></td>
<td width="12%"><strong>Datecode</strong></td>
<td width="15%"><strong>Qty.</strong></td>
</tr>
<!--循环输出查询结果数据集-->
<volist name='list' id='vo' >
<tr>
<td width="10%">{$vo.partid}</td>
<td width="38%">{$vo.partno}</td>
<td width="25%">{$vo.mfg}</td>
<td width="12%">{$vo.datecode}</td>
<td width="15%">{$vo.qty} <IMG SRC="../Public/images/del.gif" WIDTH="20" HEIGHT="20" BORDER="0" style="cursor:pointer" ALT="" onclick="delStock('{$vo.partid}')" align="absmiddle"></td>
</tr>
</volist>
</table>
<include file="Public:footer" />
再看控制器代码:
// 数据写入操作
public function insert() {
$Stk = D('Stock');
$Stk->create();
if($result=$Stk->add()) {
$this->ajaxReturn($result,"型号增加成功!",1);
}else {
$this->error("型号增加失败!");
}
}
public function delete() {
$Stk = M('Stock');
$condition['partid'] = $_REQUEST['partid'];
if ($Stk->where($condition)->delete()) {
$this->ajaxReturn($partid, $partid."型号删除成功!", 1);
}else {
$this->error($Stk->getError());
}
}
$this->ajaxReturn($result,"型号增加成功!",1);
第一个是返回的数据变量,第二个是返回的信息,第三个是数据返回的状态。
重点函数2:
ThinkAjax.send('__APP__/Index/delete/','ajax=1&partid='+partid,delComplete,'result');
第一个参数:在控制器里面的函数名称
第二个参数:需要传递的参数ajax=1好像不可少
第三个参数:提交成功执行的函数名称
第四个参数,就是显示“数据处理中~”这些提示信息的Div的名称。
重点函数3:
ThinkAjax.sendForm('frmpart','__APP__/Index/insert',addComplete,'result');
第一个参数代表提交名称为frmpart的表单
第二是参数是提交的地址
第三个参数,如果提交成功,执行的函数名称
第四个参数,就是显示“数据处理中~”这些提示信息的Div的名称。
<div id="result" class="none result" style="float:right;font-family:微软雅黑,Tahoma;width:150px;letter-spacing:2px"></div>
function addComplete(data,status)
其中的data参数,就是我们提交成功之后的返回值
$this->ajaxReturn($result,"型号增加成功!",1);
那么,data就是变量$result的值,sataus就是最后的这个参数"1"或者"0"
当然,别忘了在用ThinkAJAX的时候写上
XML/HTML代码
<load href="__PUBLIC__/Js/Base.js" />
<load href="__PUBLIC__/Js/prototype.js" />
<load href="__PUBLIC__/Js/mootools.js" />
<load href="__PUBLIC__/Js/Ajax/ThinkAjax.js" />
下面是代码
先看模板文件代码(着重看红色部分代码):
<tagLib name="html" />
<include file="Public:header" />
<SCRIPT LANGUAGE="JavaScript">
<!--
function addStock(){
ThinkAjax.sendForm('frmpart','__APP__/Index/insert',addComplete);
}
function addComplete(data,status){
if (status==1)
{
window.setTimeout(function (){window.location.href='__URL__',20000});
}
}
function delStock(partid){
ThinkAjax.send('__APP__/Index/delete/','ajax=1&partid='+partid,delComplete);
}
function delComplete(data,status){
if (status==1)
{
window.setTimeout(function (){window.location.href='__URL__',20000});
}
}
//-->
</SCRIPT>
<table width="80%" border="1" cellspacing="0" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<!--数据新增表单-->
<form name=frmpart>
<tr bgcolor='#E8E8E8'>
<td width="10%"><input type="hidden" name="ajax" value="1"><input type="button" value="新增数据" onclick="addStock()"></td>
<td width="38%">型号:<input type="text" id="partno" name="partno">
<div id="result" class="none result" style="float:right;font-family:微软雅黑,Tahoma;width:150px;letter-spacing:2px"></div>
</td>
<td width="25%">厂家:<input type="text" id="mfg" name="mfg"></td>
<td width="12%">批号:<input type="text" id="datecode" name="datecode"></td>
<td width="15%">数量:<input type="text" id="qty" name="qty"></td>
</tr>
</form>
<tr bgcolor='#E8E8E8'>
<td width="10%"><strong>ID</strong></td>
<td width="38%"><strong>PartNo.</strong></td>
<td width="25%"><strong>Mfg.</strong></td>
<td width="12%"><strong>Datecode</strong></td>
<td width="15%"><strong>Qty.</strong></td>
</tr>
<!--循环输出查询结果数据集-->
<volist name='list' id='vo' >
<tr>
<td width="10%">{$vo.partid}</td>
<td width="38%">{$vo.partno}</td>
<td width="25%">{$vo.mfg}</td>
<td width="12%">{$vo.datecode}</td>
<td width="15%">{$vo.qty} <IMG SRC="../Public/images/del.gif" WIDTH="20" HEIGHT="20" BORDER="0" style="cursor:pointer" ALT="" onclick="delStock('{$vo.partid}')" align="absmiddle"></td>
</tr>
</volist>
</table>
<include file="Public:footer" />
再看控制器代码:
// 数据写入操作
public function insert() {
$Stk = D('Stock');
$Stk->create();
if($result=$Stk->add()) {
$this->ajaxReturn($result,"型号增加成功!",1);
}else {
$this->error("型号增加失败!");
}
}
public function delete() {
$Stk = M('Stock');
$condition['partid'] = $_REQUEST['partid'];
if ($Stk->where($condition)->delete()) {
$this->ajaxReturn($partid, $partid."型号删除成功!", 1);
}else {
$this->error($Stk->getError());
}
}
0 0
- ThinkAjax的用法解析及实例
- ThinkAjax的用法解析及实例
- OSVERSIONINFO的用法及实例
- Oracle job的用法的实例解析
- Java的clone()用法实例解析
- C++中vector的用法实例解析
- C++中vector的用法实例解析
- vector的用法实例解析C++
- C++中vector的用法实例解析
- C++中vector的用法实例解析
- java cookies 的用法及实例
- CvMat的用法详解及实例
- CvMat的用法详解及实例
- getsockname和getpeername的用法及实例
- android的CursorLoader用法小结及实例
- HttpServletRequest对象方法的用法及实例
- UILabel类的用法及实例
- HttpSessionListener, HttpSessionAttributeListener的用法及简单实例
- C++中的栈和队列
- Handler sendMessage 与 obtainMessage (sendToTarget)比较
- zoj 3862 Intersection (技巧题)
- [leetcode]Construct Binary Tree from Preorder and Inorder Traversal(根据前序、中序遍历确定一棵二叉树 C语言)
- sql
- ThinkAjax的用法解析及实例
- 算法分析渐进符号(O、o、Θ、Ω、ω)总结
- 正则表达实现rss解析
- 开始练习SQL啦
- jsp 应用根目录
- HTTP返回码总结
- 欢迎使用CSDN-markdown编辑器
- Java scanner使用
- 关系型数据库设计