Jquery Autocomplete JSON string parsing error

前端 未结 2 1883
孤街浪徒
孤街浪徒 2021-01-16 07:08

I want to use Jquery autocomplete in my web application but encounter issues. I am developing my application in ASP.NET and JQuery.

Here\'s the part of the Autocopm

相关标签:
2条回答
  • 2021-01-16 07:19

    You're right -- your JSON is an array which contains a single object. You're expecting just that object.

    Try modifying your code like so:

    success: function (data) {
      data = data[0]; 
    
    0 讨论(0)
  • 2021-01-16 07:25

    I simply suggest you instead of using any other method you can use :

    success: function (data, status, xhr) {
        var jsonArray = JSON.parse(data);  // Normal way
    }
    

    Other way

    success: function (data, status, xhr) {
        var jsonArray = $.parseJSON(data); // using jQuery
    }
    

    In this way it will be converted to a simple JavaScript object which you can easily manipulate on your UI/DOM.

    0 讨论(0)
提交回复
热议问题