{"id":243053,"date":"2017-03-16T06:52:28","date_gmt":"2017-03-16T06:52:28","guid":{"rendered":"https:\/\/ru.wordpress.org\/support\/topic\/%d0%bf%d0%be%d1%87%d0%b5%d0%bc%d1%83-%d1%82%d0%be%d0%bb%d1%8c%d0%ba%d0%be-%d0%b8%d0%bd%d0%be%d0%b3%d0%b4%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d1%8b%d0%b5-%d0%bf%d0%b5%d1%80%d0%b5%d0%b4%d0%b0%d1%8e%d1%82\/"},"modified":"2017-03-16T06:52:28","modified_gmt":"2017-03-16T06:52:28","slug":"%d0%bf%d0%be%d1%87%d0%b5%d0%bc%d1%83-%d1%82%d0%be%d0%bb%d1%8c%d0%ba%d0%be-%d0%b8%d0%bd%d0%be%d0%b3%d0%b4%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d1%8b%d0%b5-%d0%bf%d0%b5%d1%80%d0%b5%d0%b4%d0%b0%d1%8e%d1%82","status":"publish","type":"topic","link":"https:\/\/ru.wordpress.org\/support\/topic\/%d0%bf%d0%be%d1%87%d0%b5%d0%bc%d1%83-%d1%82%d0%be%d0%bb%d1%8c%d0%ba%d0%be-%d0%b8%d0%bd%d0%be%d0%b3%d0%b4%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d1%8b%d0%b5-%d0%bf%d0%b5%d1%80%d0%b5%d0%b4%d0%b0%d1%8e%d1%82\/","title":{"rendered":"\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e ajax? (\u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/i.stack.imgur.com\/oICx3.png\" alt=\"\u0444\u043e\u0440\u043c\u0430\" \/><br \/>\nId \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430: fld_5264117_1, \u0430 \u0443 \u043d\u0438\u0436\u043d\u0435\u0433\u043e: fld_5733170_1.<br \/>\n\u042f \u0445\u043e\u0447\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0440\u0435\u0433\u0438\u043e\u043d\u0430 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u044f\u0437\u0438 \u043f\u043e ajax \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b\u0438\u0441\u044c localities (\u043a\u0430\u0436\u0434\u044b\u0439 region \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0432\u043e\u0438 localities). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<br \/>\n1) \u0441\u043a\u0440\u0438\u043f\u0442<\/p>\n<pre><code>jQuery(document).ready(function ($) {\n    function fill_region_selector() { \/\/\u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u044b\u0431\u043e\u0440\u0430 \u0440\u0435\u0433\u0438\u043e\u043d\u043e\u0432   \n        $.post(my_ajax_obj.ajax_url, {\n            _ajax_nonce: my_ajax_obj.nonce,\n            action: &quot;get_regions&quot;,\n        }, function (data) {\n            $(&quot;#fld_5264117_1&quot;).empty();\n             $(&quot;#fld_5264117_1&quot;).append(&#039;&lt;option value=&quot;&quot; selected disabled&gt;Please select a region...&lt;\/option&gt;&#039;)\n            for (num in data) {\n                $(&quot;#fld_5264117_1&quot;).append($(&#039;&lt;option&gt;&#039;,\n                    {\n                        value: data[num],\n                        text: data[num],\n                    }));\n            }\n        });\n    }\n    fill_region_selector();\n\n   $(&quot;#fld_5264117_1&quot;).change(function () {\n        $.post(my_ajax_obj.ajax_url, {\n            _ajax_nonce: my_ajax_obj.nonce,\n            action: &quot;get_localities_for_region&quot;,\n            region: this.value\n        }, function (data) {\n            $(&#039;#fld_5733170_1&#039;).empty();\n            for (num in data) {\n                $(&#039;#fld_5733170_1&#039;).append($(&#039;&lt;option&gt;&#039;,\n                    {\n                        value: data[num],\n                        text: data[num],\n                    }));\n            }\n        });\n    });\n\n}<\/code><\/pre>\n<p>2) \u043f\u043b\u0430\u0433\u0438\u043d (\u0434\u043b\u044f wordpress):<\/p>\n<pre><code>&lt;?php\n\n\/*\nPlugin Name: patfron\nDescription: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0430\u0439\u0442\u0430\nVersion: 1.0\nAuthor: pynix\n*\/\n\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;enqueue_trip_planner_page&#039; );\nfunction enqueue_trip_planner_page() {\n    if ( ! is_page( &#039;trip-planner&#039; ) ) {\n        return;\n    }\n    wp_enqueue_script( &#039;ajax-script&#039;,\n        plugins_url( &#039;\/js\/trip_planner_ajax.js&#039;, __FILE__ ),\n        array( &#039;jquery&#039; ) );\n\n    $my_nonce = wp_create_nonce( &#039;dzmitry_nonce&#039; );\n    wp_localize_script( &#039;ajax-script&#039;, &#039;my_ajax_obj&#039;, array(\n        &#039;ajax_url&#039; =&gt; admin_url( &#039;admin-ajax.php&#039; ),\n        &#039;nonce&#039;    =&gt; $my_nonce,\n    ) );\n}\n\nadd_action( &#039;wp_ajax_get_regions&#039;, &#039;get_regions_ajax_handler&#039; ); \/\/wp_ajax_ \u0438 \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438\nfunction get_regions_ajax_handler() {\n    check_ajax_referer( &#039;dzmitry_nonce&#039; );\n    $regions = [];\n    $pfdb = new wpdb(&#039;fdb_user&#039;,&#039;fdb_user_pass&#039;,&#039;fdb&#039;,&#039;ssssiiii.ipagemysql.com&#039;);\n\n    foreach( $fdb-&gt;get_results(&quot;SELECT name FROM Regions;&quot;) as $key =&gt; $row) {\n        $var = $row-&gt;name;\n        array_push($regions, $var);\n\n    }\n    wp_send_json( $regions );\n}\n\nadd_action( &#039;wp_ajax_get_localities_for_region&#039;, &#039;get_localities_for_region_ajax_handler&#039; ); \/\/wp_ajax_ \u0438 \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438\nfunction get_localities_for_region_ajax_handler() {\n    check_ajax_referer( &#039;dzmitry_nonce&#039; );\n\n    $region = $_POST[&#039;region&#039;];\n    $localities = [];\n    $fdb = new wpdb(&#039;fdb_user&#039;,&#039;fdb_user_pass&#039;,&#039;fdb&#039;,&#039;ssssiiii.ipagemysql.com&#039;);\n    foreach (\n        $fdb-&gt;get_results( &quot;\n                             SELECT\n                             Localities.name\n                             FROM Localities\n                             INNER JOIN Regions\n                             ON Localities.region_id = Regions.region_id\n                             WHERE Regions.name = &#039;&quot; . $region . &quot;&#039;;&quot;) as $key =&gt; $row\n    ) {\n\n                $reg = $row-&gt;name;\n        array_push($localities, $reg);\n    }\n    wp_send_json( $localities );\n}<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435.<br \/>\n\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u0440\u0430\u0432\u0434\u0430 \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0443\u043b\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438: \u0438\u043b\u0438 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u043e\u0447\u0438\u0449\u0430\u044e \u0431\u0440\u0430\u0443\u0437\u0435\u0440, \u0438\u043b\u0438 \u0438\u0437-\u0437\u0430 \u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438\/\u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430, \u0438\u043b\u0438 \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e-\u0442\u043e \u0435\u0449\u0435.<br \/>\n\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u044d\u0442\u043e \u0432\u0441\u0435 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0435. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b (\u0431\u0435\u0440\u0435\u0442 \u0438\u0437 \u0431\u0430\u0437\u044b \u043f\u043e ajax):<br \/>\n<img decoding=\"async\" src=\"https:\/\/i.stack.imgur.com\/HCMR1.png\" alt=\"\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b\" \/><\/p>\n<p>\u042f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u0442\u0443\u0442 \u0442\u044f\u0436\u0435\u043b\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e, \u043d\u043e \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0438\u0442\u0435, \u0432 \u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0447\u0442\u043e \u0431\u044b \u044f \u0441\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0441\u044f. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.stack.imgur.com\/0LShp.png\" alt=\"\u043f\u043b\u0430\u0433\u0438\u043d\" \/><\/p>\n","protected":false},"template":"","class_list":["post-243053","topic","type-topic","status-publish","hentry","topic-tag-ajax","topic-tag-jquery","topic-tag-plugin"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/243053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/243053\/revisions"}],"wp:attachment":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=243053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}