JS-json-1
To process the smarty template as ajax, You Need To splice an html file to append the node.
Previously, the smarty array needs to be processed as json data and returned. The changes on the server side are relatively small:
header(Content-type : application/json)echo json_encode($arr);
The front-end processing is also very simple
$.ajax({ url : http://example.com, type : GET, dataType : json, data : { //some data }, success : function(data){ //blog theme }});
The above is all nonsense. I have said so much, but it is not guaranteed to be correct. I have no documents at hand, so I wrote a blind look. The following is the topic:
Error 1:
Sometimes the format returned by json is as follows:
{210 : {a,b,c},220 : {a : 110 , b : lolo}}
If I use
for(var i = 0; i < data.length; i++ )
In this way, an error is reported because data does not have the length attribute. You should use the following methods to traverse data:
for(var obj in data)
: It indicates whether the property of the object exists.
We need to explicitly put forward that obj represents the key, so you actually need:
data[obj]
But this is obviously an array access method.
Error 2:
var img = data.img;var imgLen = data.img.length;
If the img attribute is not saved, the undefined object is returned. Here, the undefined object does not have the length attribute. Use it when I block it
if(!data.img.length)
This is actually not possible, because it is a mistake.
A json-handle plug-in is recommended.