$.ajax returns JSON data and cannot be successfully resolved

Source: Internet
Author: User
Tags eval

Note: Must be changed to write: "{" Success ": true," MESG ":" Success "}", if it is bool type, without quotes, the other keys/values need to be quoted. "

$.ajax ({
..
DataType: ' JSON ',
...
Success:function (JSON) {
Do not perform success
},
Error:function (Error) {
Always execute this error
}
});


Commonly used is the $get (Url,data,callback,type) method

Where the URL is a page for the asynchronous request (which can be a. ashx file), data is a parameter, callback is a callback function, and type is the type that returns the data. Type has xml,html,json,text etc.

First, the page references Jquery.js

Write the JS function for AJAX processing on the page

function initmeeting () {
$.get ("/common/meetingroom.ashx", {meetid:<%=meetid%>},function sellerlist (data) {
$ ("#divSellerList"). HTML (data);
}, "JSON");
SetTimeout ("initmeeting ()", 20000);
}
function initmeeting () {
$.get ("/common/meetingroom.ashx", {meetid:<%=meetid%>},function sellerlist (data) {
var obj = eval ("(+ Data +)"); the converted JSON object
$ ("#divSellerList"). html (obj. Cellerlist);
}, "html");
SetTimeout ("initmeeting ()", 20000);
}

The return type I use is JSON, which returns a data type similar to the class. {"Name": "Sunny d.d", "Age": 25}

But when you use the return value data, you first convert JSON by

var obj = eval ("(+ Data +)"); the converted JSON object

You can get the JSON object.

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.