jquery fill dropdown with json data

后端 未结 4 1379
眼角桃花
眼角桃花 2020-11-28 06:51

I have the following jQuery code. I am able to get the following data from server [{\"value\":\"1\",\"label\":\"xyz\"}, {\"value\":\"2\",\"label\":\"abc\"}]. Ho

4条回答
  •  情深已故
    2020-11-28 07:29

    If your data is already in array form, it's really simple using jQuery:

     $(data.msg).each(function()
     {
         alert(this.value);
         alert(this.label);
    
         //this refers to the current item being iterated over
    
         var option = $('

    .ajax() is more flexible than .getJSON() - for one, getJson is targeted specifically as a GET request to retrieve json; ajax() can request on any verb to get back any content type (although sometimes that's not useful). getJSON internally calls .ajax().

提交回复
热议问题