Ask how PHP how to return variables + assemble HTML to Ajax

Source: Internet
Author: User
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. = '

      Recommended date: '. $row [' Zttime ']. '

      ';
      }
      $result. = '
    ;
    $result. = '

    '. $pagecon. '

    ';
    Return $result, $a, $b;
    }

You need to return the $ A variable and the $b variable and an assembled $result HTML to Ajax. If you encapsulate Ajax without JSON

Share to: 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. = '

      Recommended date: '. $row [' Zttime ']. '

      ';
      }
      $result. = '
    ;
    $result. = '

    '. $pagecon. '

    ';
    return $result. '--$a. '--' $b;//Use--to connect back
    }


function GetData (page) {
Alert (' OK ');
$.ajax ({
Type: ' Post ',
URL: ' action/test.php ',
Data: {' Pagenum ':p age-1},
Beforesend:function () {
$ ("#sss ul"). Append ("
  • Loading ...
  • ");
    },
    Success:function (JSON) {
    var arr=json.split ('--');
    $ ("#sss ul"). empty ();
    result = arr[' 0 ']//gets the variable from PHP $result
    Total = arr[' 0 ']//get variable $ A from PHP
    PageSize =//Get the variable from PHP $b
    $ ("Div#sss"). HTML (data);
    },
    Complete:function () {//RAW ingredient page strip
    Getpagebar ();
    },
    Error:function () {
    Alert ("Data load 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.