How does php return variables + assemble html for ajax-php Tutorial?

Source: Internet
Author: User
How does php return variables + assemble html to ajaxfunction & nbsp; html ($ select, $ name) {global & nbsp; $ pagecon; $ a1; $ b2; $ result; $ result. & lt; ul & nbsp; & gt; while ($ row $ select-& gt; fetch: How does php return variables + assemble html to ajax?
Function html ($ select, $ name ){
Global $ pagecon;
$ A = '1 ';
$ B = '2 ';
$ Result = '';
$ Result. ='
    ';
    While ($ row = $ select-> fetch ()){
    $ Result. ='
  • ';
    $ Result. ='

      ';
      $ Result. = ''. $ row ['ztname'].'';
      $ Result. = ''. $ row ['zttype'].'';
      $ Result. ='

      Recommendation Date: '. $ row ['zttime'].'

      ';
      }
      $ Result. ='
    ';
    $ Result. =' '. $ Pagecon .' ';
    Return $ result, $ a, $ B;
    }

$ A, $ B, and an assembled $ result html are returned to ajax. if json is not used

Share: More


------ Solution --------------------
return "$result,$a,$b";

success:function(json){
a = json.split(',');

------ Solution --------------------
Function html ($ select, $ name ){
Global $ pagecon;
$ A = '1 ';
$ B = '2 ';
$ Result = '';
$ Result. ='
    ';
    While ($ row = $ select-> fetch ()){
    $ Result. ='
  • ';
    $ Result. ='

      ';
      $ Result. = ''. $ row ['ztname'].'';
      $ Result. = ''. $ row ['zttype'].'';
      $ Result. ='

      Recommendation Date: '. $ row ['zttime'].'

      ';
      }
      $ Result. ='
    ';
    $ Result. =' '. $ Pagecon .' ';
    Return $ result. '--'. $ a. '--'. $ B; // use -- to connect and return
    }


Function getData (page ){
Alert ('OK ');
$. Ajax ({
Type: 'post ',
Url: 'Action/test. php ',
Data: {'pagenum': page-1 },
BeforeSend: function (){
$ ("# Sss ul"). append ("
  • Loading...
  • ");
    },
    Success: function (json ){
    Var arr = json. split ('--');
    $ ("# Sss ul"). empty ();
    Result = arr ['0'] // Get the variable from php $ result
    Total = arr ['0'] // Get the variable from php $
    PageSize = // Get the variable $ B from php
    $ ("P # sss" pai.html (data );
    },
    Complete: function () {// generate a page entry
    GetPageBar ();
    },
    Error: function (){
    Alert ("data loading failed ");
    }
    });
    }


    Hope to help you!

    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.