{"id":11664108,"date":"2020-05-05T10:30:06","date_gmt":"2020-05-05T01:30:06","guid":{"rendered":"https:\/\/ja.wordpress.org\/support\/topic\/wordpress-ajax%e3%81%a7%e7%b5%9e%e3%82%8a%e8%be%bc%e3%81%bf%e3%83%aa%e3%82%a2%e3%83%ab%e3%82%bf%e3%82%a4%e3%83%a0%e6%a4%9c%e7%b4%a2%e3%82%92%e3%81%97%e3%81%9f%e3%81%84\/"},"modified":"2020-05-05T10:30:06","modified_gmt":"2020-05-05T01:30:06","slug":"wordpress-ajax%e3%81%a7%e7%b5%9e%e3%82%8a%e8%be%bc%e3%81%bf%e3%83%aa%e3%82%a2%e3%83%ab%e3%82%bf%e3%82%a4%e3%83%a0%e6%a4%9c%e7%b4%a2%e3%82%92%e3%81%97%e3%81%9f%e3%81%84","status":"publish","type":"topic","link":"https:\/\/ja.wordpress.org\/support\/topic\/wordpress-ajax%e3%81%a7%e7%b5%9e%e3%82%8a%e8%be%bc%e3%81%bf%e3%83%aa%e3%82%a2%e3%83%ab%e3%82%bf%e3%82%a4%e3%83%a0%e6%a4%9c%e7%b4%a2%e3%82%92%e3%81%97%e3%81%9f%e3%81%84\/","title":{"rendered":"wordpress AJAX\u3067\u7d5e\u308a\u8fbc\u307f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u691c\u7d22\u3092\u3057\u305f\u3044"},"content":{"rendered":"<p>\u4ee5\u4e0b\u306e\u8cea\u554f\u3068\u9078\u629e\u80a2\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>Q1 A1 A2 A3<br \/>\nQ2 A2 A2 A3<br \/>\nQ3 A1 A2 A3<br \/>\nQ4 A1 A2 A3<\/p>\n<p>Q\u306f\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9<br \/>\nA\u306f\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>https:\/\/sim.hyouban-hikaku.com\/<br \/>\n\u3053\u3053\u306e\u30b5\u30a4\u30c8\u306b\u3042\u308b\u3088\u3046\u306a\u7d5e\u308a\u8fbc\u307f\u691c\u7d22\u3092\u3057\u305f\u3044\u3067\u3059\u3002<br \/>\n\u4e0a\u8a18\u30b5\u30a4\u30c8\u306f\u3059\u3067\u306b\u8868\u793a\u3055\u308c\u3066\u308b\u306e\u3092js\u3067\u30bd\u30fc\u30c8\u3057\u3066\u308b\u3060\u3051\u3067\u3059\u304c\u3001<\/p>\n<p>\u5f53\u65b9\u304c\u3084\u308a\u305f\u3044\u306e\u306f\u666e\u901a\u306e\u8a18\u4e8b\u691c\u7d22\u306e\u3088\u3046\u306bDB\u304b\u3089\u53d6\u3063\u3066\u304f\u308b\u3084\u3064\u3067\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u307e\u3067\uff08\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\uff11\u500b\uff09\u306f\u52d5\u4f5c\u3057\u307e\u3057\u305f\u304c\u3001<br \/>\n\u8907\u6570\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3060\u3068\u3084\u308a\u65b9\u304c\u308f\u304b\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3054\u6559\u6388\u304a\u9858\u3044\u3057\u307e\u3059\u3002<\/p>\n<p>js\u306e\u8a18\u8ff0<\/p>\n<pre><code>\n$(function(){\n    \/\/ 2\u91cd\u30af\u30ea\u30c3\u30af\u9632\u6b62\u30d5\u30e9\u30b0\n    var click_flag = true;\n\n    \/\/ \u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\n    $(&#039;.search_frame input&#039;).change(function(e){\n        if ( click_flag ) {\n            click_flag = false;\n            $(&#039;.result li&#039;).remove();\n            $(&#039;.result&#039;).append(&#039;&lt;li class=&quot;loading&quot;&gt;\u8aad\u307f\u8fbc\u307f\u4e2d&lt;\/li&gt;&#039;);\n\n            \/\/ \u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3067\u9078\u629e\u3055\u308c\u3066\u3044\u308bvalue\u3092\u53d6\u5f97\n            var check_01 = $(&#039;.search_frame input#l11&#039;).val();\n            \/\/alert(check_01);\n            $.ajax({\n                type: &quot;POST&quot;,\n                url: ajaxurl,\n                data: {\n                    \/\/ \u30c7\u30fc\u30bf\u53d7\u3051\u6e21\u3057\n                    &#039;check_01&#039; : check_01,\n                    &#039;action&#039; : &#039;ajax_get_posts&#039;,\n                },\n                success: function( response ) {\n                    $(&#039;.result .loading&#039;).remove();\n                    jsonData = JSON.parse( response );\n                    var count = jsonData.length;\n                    if ( count == &#039;0&#039; ) {\n                        \/\/ \u691c\u7d22\u7d50\u679c\u304c\u306a\u3044\u5834\u5408\n                        $(&#039;.result&#039;).append(&#039;&lt;li&gt;\u691c\u7d22\u7d50\u679c\u304c\u3042\u308a\u307e\u305b\u3093\u3002&lt;\/li&gt;&#039;);\n                    } else {\n                        \/\/ \u30ea\u30b9\u30c8\u306b\u51fa\u529b\n                        $.each( jsonData, function( i, val ) {\n                        $(&#039;.result&#039;).append(&#039;&lt;li&gt;&lt;a href=&quot;&#039; + val[&#039;permalink&#039;] + &#039;&quot;&gt;&#039; + val[&#039;post_title&#039;] + &#039;&lt;\/a&gt;&lt;\/li&gt;&#039;);\n                        });\n                    }\n                    click_flag = true;\n                },\n                error: function( response ) {\n                    \/\/ ajax\u30a8\u30e9\u30fc\u306e\u5834\u5408\n                    $(&#039;.result .loading&#039;).remove();\n                    $(&#039;.result&#039;).append(&#039;&lt;li&gt;\u30a8\u30e9\u30fc\u304c\u8d77\u3053\u308a\u307e\u3057\u305f\u3002\u304a\u624b\u6570\u3067\u3059\u304c\u30da\u30fc\u30b8\u306e\u518d\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3063\u3066\u304f\u3060\u3055\u3044\u3002&lt;\/li&gt;&#039;);\n                    click_flag = true;\n                }\n            });\n        }\n    });\n});\n\n<\/code><\/pre>\n<p>function\u306e\u8a18\u8ff0<\/p>\n<pre><code>\n\/\/ get_posts\u3067\u30c7\u30fc\u30bf\u3092json\u3078\nfunction ajax_get_posts(){\n    \/\/ js\u304b\u3089\u53d7\u3051\u6e21\u3057\u3059\u308b\u30c7\u30fc\u30bf\n    $select_01 = $_POST[&#039;search_frame&#039;];\n\n    $returnObj = array();\n\n    \/\/ get_posts \u30aa\u30d7\u30b7\u30e7\u30f3\n    $args = array(\n        &#039;post_type&#039; =&gt; &#039;post&#039;,\n        &#039;numberposts&#039; =&gt; -1\n    );\n    $posts = get_posts( $args );\n    foreach( $posts as $key =&gt; $post ) {\n        $returnObj[$key] = array(\n            \/\/ \u51fa\u529b\u3059\u308b\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\n            &#039;post_title&#039; =&gt; $post-&gt;post_title,\n            &#039;permalink&#039; =&gt; get_permalink( $post-&gt;ID ),\n        );\n    }\n\n    \/\/ json\u5f62\u5f0f\u306b\u51fa\u529b\n    echo json_encode( $returnObj );\n    die();\n}\nadd_action( &#039;wp_ajax_ajax_get_posts&#039;, &#039;ajax_get_posts&#039; );\nadd_action( &#039;wp_ajax_nopriv_ajax_get_posts&#039;, &#039;ajax_get_posts&#039; );\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-11664108","topic","type-topic","status-publish","hentry","topic-tag-ajax","topic-tag-js","topic-tag-wordoress"],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11664108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11664108\/revisions"}],"wp:attachment":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11664108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}