{"id":2692,"date":"2019-02-18T16:51:54","date_gmt":"2019-02-18T07:51:54","guid":{"rendered":"http:\/\/www.whoocus.com\/blog\/?p=2692"},"modified":"2019-02-18T16:53:59","modified_gmt":"2019-02-18T07:53:59","slug":"select-%e3%83%97%e3%83%ab%e3%83%80%e3%82%a6%e3%83%b3%e3%81%ae%e6%9b%b8%e3%81%8d%e6%8f%9b%e3%81%88","status":"publish","type":"post","link":"https:\/\/www.blowfish.co.jp\/?p=2692","title":{"rendered":"select \u30d7\u30eb\u30c0\u30a6\u30f3\u306e\u66f8\u304d\u63db\u3048"},"content":{"rendered":"<p>3\u5e74\u306b1\u5ea6\u306f\u5fc5\u305a\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u6280\u8853\u3002<br \/>\n\u899a\u3048\u66f8\u304d\u3067\u3059\u3002<\/p>\n<p>[html]<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;JS&lt;\/title&gt;<br \/>\n    &lt;script<br \/>\n        src=&quot;https:\/\/code.jquery.com\/jquery-3.3.1.min.js&quot; integrity=&quot;sha256-FgpCb\/KJQlLNfOu91ta32o\/NMZxltwRo8QtmkMRdAu8=&quot; crossorigin=&quot;anonymous&quot;&gt;<br \/>\n    &lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;select name=&quot;item&quot; id=&quot;item&quot;&gt;<br \/>\n    &lt;option value=&quot;&quot;&gt;\u308a\u3093\u3054&lt;\/option&gt;<br \/>\n    &lt;option value=&quot;&quot;&gt;\u30a4\u30c1\u30b4&lt;\/option&gt;<br \/>\n    &lt;option value=&quot;&quot;&gt;\u30d0\u30ca\u30ca&lt;\/option&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<p>&lt;script&gt;<br \/>\n    $(function(){<br \/>\n        $(&#8216;#item&#8217;).change(function(){<br \/>\n            $.ajax({<br \/>\n        \t\turl:&quot;\/data.json&quot;,<br \/>\n        \t\ttype:&quot;POST&quot;,<br \/>\n                data:$(&quot;#form1&quot;).serialize(),<br \/>\n\t\t        dataType:&quot;json&quot;,<br \/>\n\t\t        timespan:1000<br \/>\n    \t\t}).done(function(data1,textStatus,jqXHR) {<br \/>\n\t\t\t\tconsole.log(jqXHR.status);<br \/>\n\t\t\t\tconsole.log(textStatus);<\/p>\n<p>                console.log(data1);<br \/>\n                console.log(data1[&quot;data&quot;][0].name);<\/p>\n<p>                var data2 = JSON.stringify(data1);<br \/>\n\t\t\t\tconsole.log(data2); <\/p>\n<p>                var data3 = JSON.parse(data2);<br \/>\n\t\t\t\tconsole.log(data3);<\/p>\n<p>                $(&quot;#item option&quot;).remove();<br \/>\n                $(&quot;#item&quot;).append(&quot;&lt;option&gt;&lt;\/option&gt;&quot;);<br \/>\n                $.each(data3[&quot;data&quot;], function(key, value){<br \/>\n                    console.log(key + &#8216;:&#8217; + value);<br \/>\n                    $(&quot;#item&quot;).append($(&quot;&lt;option&gt;&quot;).val(value.id).text(value.name));<br \/>\n                });<br \/>\n            }).fail(function(jqXHR, textStatus, errorThrown ) {<br \/>\n                console.log(jqXHR.status);<br \/>\n                console.log(textStatus);<br \/>\n                console.log(errorThrown);<br \/>\n                console.log(&#8216;Failed&#8217;);<br \/>\n            }).always(function(){<br \/>\n                console.log(&quot;complete&quot;);<br \/>\n            });<br \/>\n        });<br \/>\n    });<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n[\/html]<\/p>\n<p>[javascript]<br \/>\n{&quot;data&quot; : [<br \/>\n    {<br \/>\n        &quot;id&quot; : &quot;1&quot;,<br \/>\n        &quot;name&quot; : &quot;\u592a\u90ce&quot;,<br \/>\n        &quot;age&quot; : &quot;12&quot;<br \/>\n    },<br \/>\n    {<br \/>\n        &quot;id&quot; : &quot;2&quot;,<br \/>\n        &quot;name&quot; : &quot;\u82b1\u5b50&quot;,<br \/>\n        &quot;age&quot; : &quot;14&quot;<br \/>\n    },<br \/>\n    {<br \/>\n        &quot;id&quot; : &quot;3&quot;,<br \/>\n        &quot;name&quot; : &quot;\u91d1\u592a\u90ce&quot;,<br \/>\n        &quot;age&quot; : &quot;32&quot;<br \/>\n    },<br \/>\n    {<br \/>\n        &quot;id&quot; : &quot;4&quot;,<br \/>\n        &quot;name&quot; : &quot;\u6843\u592a\u90ce&quot;,<br \/>\n        &quot;age&quot; : &quot;47&quot;<br \/>\n    },<br \/>\n    {<br \/>\n        &quot;id&quot; : &quot;5&quot;,<br \/>\n        &quot;name&quot; : &quot;\u8d64\u592a\u90ce&quot;,<br \/>\n        &quot;age&quot; : &quot;23&quot;<br \/>\n    }<br \/>\n]}<br \/>\n[\/javascript]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3\u5e74\u306b1\u5ea6\u306f\u5fc5\u305a\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u6280\u8853\u3002 \u899a\u3048\u66f8\u304d\u3067\u3059\u3002 [html] &lt;html&gt; &lt;head&gt; &lt;title&gt;JS&lt;\/title&gt; &lt;script src=&#038;qu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"footnotes":""},"categories":[10,33,4],"tags":[],"class_list":["post-2692","post","type-post","status-publish","format-standard","hentry","category-javascript","category-jquery","category-tech"],"_links":{"self":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2692"}],"version-history":[{"count":3,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2692\/revisions"}],"predecessor-version":[{"id":2695,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2692\/revisions\/2695"}],"wp:attachment":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}