Using jquery Ajax requires attention to the local datatype settings _jquery

Source: Internet
Author: User
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.
Related Article

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.