Click Submit. You do not need to refresh this page, submit the content to the database, and display the submitted content on this page.
Jquery method:
Messageaction. Class. php
<? PHP
Class messageaction extends action {
Function Index (){
$ This-> display ();
}
Function add (){
// Ajaxreturn (data, 'prompt information', status)
$ M = m ('message ');
If ($ M-> Add ($ _ Get )){
$ This-> ajaxreturn ($ _ Get, 'information added successfully', 1 );
} Else {
$ This-> ajaxreturn (0, 'failed to add information', 0 );
}
}
}
?>
Template index.html
<HTML>
<Head>
<SCRIPT type = "text/JavaScript" src = "_ Public _/JavaScript/jquery-1.7.1.min.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
$ (Function (){
$ ('Input: click'). 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 (){
Optional mess.css ('display', 'block ');
Registrant .html ('title is '+ JSON. Data. Title +' information is '+ JSON. Data. Message );
} Else {
$ Mess. slidedown (3000, function (){
Optional mess.css ('display', 'block ');