Yesterday I was having problems doing Ajax,
Copy Code code as follows:
<span style= "White-space:pre" >
</span>$.ajax ({
URL: ' <{$weburl}>/main.php?action=getdepart&cid= ' +cid,
Type: ' Post ',
DataType: ' JSON ',
Success:function (data) {
Data=eval (' (' +data+ ') ');
if (data.s==1)
{
$ (' #depart '). html (');
$ (' #depart '). HTML (data.departs);
}
Else
{
Alert (' acquisition of the faculties failed ');
}
}
});
Not particularly aware of this problem before, at first without setting datatype: ' JSON ', there is the inability to parse the returned data, which will treat data as a string instead of a JSON object, all of which I use Eval to convert, And in the server because the data sent back contains a lot of HTML tags, also can not read correctly, resulting in data error, I remember the previous is no need to set datatype, very strange, do not know is not with the jquery version of the relationship, it seems that the later or clearly set the datatype better.