json - jquery autocomplete throws --> "parsererror", SyntaxError: invalid label -


following official example autocomplete, came this.

$("#search").autocomplete({             source: function (request, response) {                 $.ajax({                     url: "/search",                     datatype: "jsonp",                     data: {                         featureclass: "p",                         style: "full",                         maxrows: 12,                         name_startswith: request.term                     },                     success: function (data) {                         response($.map(data.username, function (item) {                             return {                                 label: item.name,                                 value: item.name                             };                         }));                     },                     error: function (data) {                      }                 });             },             minlength: 2,             select: function (event, ui) {              },          }); 

however never hit success: function (data) { .. } error: function (data) {.

firebug shows error: "parsererror", syntaxerror: invalid label

enter image description here

the /search url produces on server side:

def search():     data = none     if 'name_startswith' in request.args:         q = request.args['name_startswith']         data = user.query(ndb.and(user.firstname >= q, user.firstname <= q + u'\ufffd')).fetch(12)         js = []         user in data:             js.append({'name' : user.fullname()})              return jsonify(username=js) 

any suggestions please?

change datatype json because response json object , request sent same domain there no need jsonp

$("#search").autocomplete({             source: function (request, response) {                 $.ajax({                     url: "/search",                     datatype: "json",                     data: {                         featureclass: "p",                         style: "full",                         maxrows: 12,                         name_startswith: request.term                     },                     success: function (data) {                         response($.map(data.username, function (item) {                             return {                                 label: item.name,                                 value: item.name                             };                         }));                     },                     error: function (data) {                      }                 });             },             minlength: 2,             select: function (event, ui) {              },          }); 

demo: error demo: solution


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -