javascript - How to use getJSON with this code -


I have found this select box which uses JSON data to populate the option. . The data is hard, but I want to load the data using the $ .getJSON () method, but I can not find the right code. I think the suggest.json file has started, but There is some other problem happening. Will someone show me to fix this problem?

I found the drop down box

Original code:

    

This is my failed attempt:

  & lt; Script type = "text / javascript" & gt; $ .getJSON ('suggest.json', function (data) select {var $ = $ ('# mySelectID'); $ .eee (data, function (index, o) {var $ option = $ (" Lt; option />").attr("value ", o.CODE) .text (o.box1 +" | "+ o.id); $ select.append ($ option);})}}); JQuery ("# ​​mySelectID") dynamicDropdown ({"delimiter": "|"}} & Lt; / Script & gt;   

Suggest.JSON:

  [{"box 1": "Africa", "code": 1, "id": "A"} , "Code": 3, "id": "c": {"box 1": "Asia", "code": 2, "id": "b"}, {"box 1": "south america", "code" The problem is that you get the value of  $ ("# mySelectID");    

only when getJSON returns data to you

According to your code, simply swap the plugin call :

  $ (document) .ready (function () {$ .getJSON ('my.json', function) {var $ select = $ ('# mySelectID'); $.eitch (data, function (index, o) {var $ option = $ ("& lt; option />"). Attr ("value", o.code) .text (obox1 + "| "OAID"); $ APPEND ($ option);}); $ ("# mySelectID"). Dynamic DROPDOWN ({"" "Delimiter": "|"});});});  By the way, you have an error with your Jason: the last item ("South America") is "code" and according to others the code "note"   

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -