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.