Thinkphp Learning Notes (15) Use Ajax and jquery to implement page no refresh ____php

Source: Internet
Author: User

Action

<?php
class Messageaction extends action{public
  	function Index () {
    	$this->display ();
    }  
  	Public Function jquery () {
    	$this->display ();
    }  
    Public function Add () {
    	$m =m (' message ');
    	if ($vo = $m->create ()) {
    		if ($m->add ()) {
//    			$this->success (' Add success ');
				Use Ajax
    			$this->ajaxreturn ($vo, ' Add success ', 1);
    		} else{
//    			$this->error (' Add failed ');
				Use Ajax
    			$this->ajaxreturn (0, ' Add failed ', 0);
    		}
    	else{
    		$this->error ($m->geterror ());
    	}
    Public Function Addjquery () {
    	//ajaxreturn ()
    	//Return JSON Format data
    	//parameter one: data; parameter two: hint information; three: status
    	//echo $ This->ajaxreturn (3, ' hint info ', 2);
    	$m =m (' message ');
    	if ($m->add ($_get)) {
    		$this->ajaxreturn ($_get, ' Add information succeeded ', 1);
    	} else{
    		$this->ajaxreturn (0, ' Add info failed ', 0);
    	}
    }
? >

Jquery.html

<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  

Index.html

<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.