Hey guys, I have a question about ajax returning json. thank you for choosing the php Tutorial.

Source: Internet
Author: User
Hey guys, I have a question about ajax returning json. thank you! This post was last edited by gxnnlj6 from 2015-09-1712: 43: 57 & lt; li & nbsp; & gt; & lt; li & gt; & nbsp; & nbsp!

This post was last edited by gxnnlj6 at 12:43:57 on


  • $. Ajax ({
    Type: "POST ",
    Url: "class. php ",
    Data: "bid =" + bid,
    Success: function (data ){
    $ ("# Xlm2" ).html ("classification:" + data );
    }
    });

    while($r=$cms->fetch($mesql)){ 
    $classname.= $r[classname];
    }
    echo $classname;


    In this way, the output is normal:
  • Category: Column 1, column 2, column 3 ......


  • Now I want to output one more topic Image:

  • Category: Column 1, column 2, column 3 ......


  • How should I change it?



  • $. Ajax ({
    Type: "POST ",
    Url: "class. php ",
    Data: "bid =" + bid,
    DataType: "json ",
    Success: function (data ){
    $ ("# Xlm1" ).html ("");
    $ ("# Xlm2" ).html ("classification:" + data );
    }
    });

    while($r=$cms->fetch($mesql)){ 
    $classname.= $r[classname];
    $img= $r[img];
    }
    echo json_encode(......);

    ------ Solution ----------------------
    While ($ r = $ cms-> fetch ($ mesql )){
    $ Classname. = $ r [classname];
    $ Img = $ r [img];
    }
    Echo json_encode (array ('data' => $ classname, 'IMG '=> $ img );
    ------ Solution ----------------------
    How to write? Based on your needs

    It seems that you are not talking about js, so you can assemble html in php and then return it. Don't use any json (same as your first example)

    In fact, if JavaScript is used to assemble HTML, it is better to use php to assemble HTML.

    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.