jquery's autocomplete plugin's remote URL takes JSON data out of the question

Source: Internet
Author: User

About the remote return of the JSON data display, the same code, if the local write JSON string data, plug-in display there is no problem, once replaced by ULR way to read the same data, plug-ins can not display the problem properly.

The occasional search for information today to find a question on the CSDN, is the same problem

Http://topic.csdn.net/u/20090703/14/8d349262-8ca1-4bf5-998d-3a0712412149.html

There's an expert in the solution

$ ("#autocomplete"). AutoComplete ("Data.aspx", {
minchars:0,
Max:15,
WIDTH:200,
Scroll:false,
SCROLLHEIGHT:500,
Need to convert data into JSON data format
Parse:function (data) {
if (Data! = "") {
Return $.map (eval (data), function (row) {
return {
Data:row,
Value:row.name,
Result:row.name + "<" + row.to + ">"
}
});
}
},
Formatitem:function (data, I, total) {
Return "<div style= ' Float:left ' >" +data.name+data.to+ "</div>"
},
Formatmatch:function (data, I, total) {
return data.name;
},
Formatresult:function (data, value) {
return data.name;
}
}). result (function (event, data, formatted) {
$ ("#twoColum_abbr"). Val (data.to);
});

After the data is returned, it is time to process

The key point is

You need to convert data to JSON data format, note that you must determine if data is empty, otherwise out of the ordinary, the following red callout
Parse:function (data) {
if (Data! = "") {
Return $.map (eval (data), function (row) {
return {
Data:row,
Value:row.name,
Result:row.name + "<" + row.to + ">"
}
});
}
},

This way, you can manipulate the data normally.

jquery's autocomplete plugin's remote URL takes JSON data out of the question

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.