ajax - Unexpected token < in JSON at position 2 jquery Autocomplete -


i have ajax request jquery "autocomplete", code bellow:

    var clienteslist = [];      $("#clientes").autocomplete({         source: function (request, callback) {             $.ajax({                 type: "post",                 url: "../../../cliente/getclientesbyname",                 data: "{'nome':'" + request.term + "'}",                 contenttype: "application/json; charset=utf-8",                 datatype: "json",                 success: function (data) {                     debugger;                     callback($.map(data.cities, function (obj) {                         return obj.main                     }))                 }             })         }     }) 

when event triggered, error showed in jquery.min??

"create:2 uncaught syntaxerror: unexpected token < in json @ position 2"

my input html this:

<input type="text" id="clientes" class="form-control col-md-10" /> 

my guess due malformed json data property, server-side resource returning html error, hence unexpected < character in response.

fix data creating valid json string...

data: json.stringify({nome: request.term}), 

this produce value like

{"nome":"whatever typed"} 

which valid instead of

{'nome':'whatever typed'} 

which not due single-quotes , possibly worse depending on value of request.term.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -