The first of these methods
The second method of
jquery method: Messageaction.class.php<?Phpclass Messageaction extends action{function index () {$this->display (); } function Add () {//ajaxreturn (data, ' hint information ', state) $m =m (' message '); if ($m->add ($_get)) {$this->ajaxreturn ($_get, ' Add information succeeded ', 1); }else{$this->ajaxreturn (0, ' Add information failed ', 0); }}}?> template index.HtmlJavaScriptSrc= "__public__/js/jquery-1.7.1.min.js" ></script><script type= "Text/javascript" > $ (Function () {$ ( ' Input:button '). Click (function () {var $title =$ (' input[name= "title"] '). Val (); var $message =$ (' input[name= ' "message"]). Val (); $mess =$ (' #mess '); $.getjson (' __url__/add ', {title: $title, Message: $message},function (JSON) {//alert (JSON); return false; if (JSON.status==1) {$mess. Slidedown (3000,function () {$mess. css (' Display ', ' block '); }). html (' title ' +json.data.title+ ' information for ' +json.data.message '); }else{$mess. Slidedown (3000,function () {$mess.CSS (' Display ', 'Block '); }). html (' information added failed, please check '); } }); })}) </script></Head><body><divStyle= "Display:none; color:red; "id=" mess "></div><form action=" "method=" Get "> title: <input type=" text "name=" title "/> <br/> Info: <input type= "text" name= "message"/><br/> <input type= "button" value= "Commit"/></form ></body>Phpclass Messageaction extends action{function index () {$this->display ()} function Addtwo () {$m =m (' message '); if ($v o= $m->create ()) {if ($m->add ()) {$this->ajaxreturn ($vo, ' Add succeeded ', 1);} else{$this->ajaxreturn (0, ' Add failed ', 0);}} else{$this->error ($m->geterror ());}} }?> Template index.html<html>JavaScript" src= "__public__/js/base.js" > </script><script type= "Text/javascript" src= "__public__/js/prototype.js" ></script><script Type= "Text/javascript" src= "__public__/js/mootools.js" ></script><script type= "Text/javascript" src= "_ _public__/js/thinkajax.js "></script><script type=" Text/javascript "> Function Add () {// Thinkajax.sendform (Form Id,url, callback function, where information is displayed); Thinkajax.sendform (' frm ', ' __url__/addtwo ', WC); } function WC (data,status) {if (status!=1) {alert (' send failed ');} else{$ (' list '). innerhtml+= ' title ' +data.title+ ', Information ' +data.message;}} </script></head><body>
Several types of Ajax commonly used by JQ and thinkphp