JSONPの書式を自前で用意するときとそれを呼び出すとき
JSONPの書式を自前で用意するときとそれを呼び出すとき
callback( {"category":[ {"catid": "001","catname": "test1"}, {"catid": "002","catname": "test2"}, {"catid": "003","catname": "test3"}, {"catid": "004","catname": "test4"}, {"catid": "005","catname": "test5"} ] }, {"category_origin": [ {"catid": "001","catname": "test1"}, {"catid": "002","catname": "test2"}, {"catid": "003","catname": "test3"}, {"catid": "004","catname": "test4"}, {"catid": "005","catname": "test5"} ] } ); $(function(){ $.getJSON('http://hogehoge.com/sample.json?callback=?') }); var callback = function(data){ var obj; $(data.category).each(function(key,value){ var val = this.catid; var text = this.catname; obj += '<option val="' + val + '">' + text + '</option>'; }); $('#form_cat').html(obj); };