{"id":164443,"date":"2013-01-05T12:56:03","date_gmt":"2013-01-05T08:56:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=164443"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=164443","title":{"rendered":"<span class=\"post_title\">\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 ajax \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 Drupal 7<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e \u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435 \u0448\u043b\u044e\u0442 ajax \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0440\u0443\u043a\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e $.ajax(), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 Drupal \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u044f\u0434\u0440\u0430, \u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e JS \u043a\u043e\u0434\u0430.<br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0432\u0435\u0449\u0430\u043c\u0438 \u043a\u0430\u043a delivery callback, Drupal.ajax \u0438 JS-commands.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>Delivery callback<\/h4>\n<p>  \u041e\u043f\u0438\u0448\u0443 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b.<br \/>  \u0412 D6 \u0432\u0430\u0448 \u043c\u0435\u043d\u044e \u043a\u043e\u043b\u0431\u0435\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 html, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u0432 theme(&#8216;page&#8217;, $content), \u0438 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443.<br \/>  \u0427\u0442\u043e \u0431\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 json-\u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0438\u043d\u0443\u044f page.tpl, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c drupal_json($result), \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 exit().<br \/>  \u0412 D7 \u0432\u0432\u0435\u043b\u0438 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u2014 &#8216;delivery callback&#8217;. \u0421\u0443\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u043d\u044e \u043a\u043e\u043b\u0431\u0435\u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 (\u0441\u043c. <a href=\"http:\/\/drupal.org\/node\/930760\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u043d\u0434\u0435\u0440-\u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u043f\u0430\u043b.\u043e\u0440\u0433<\/a>), \u0430 \u0443\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 hook_menu \u043a\u0430\u043a delivery callback, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u043a\u0430\u043a \u043e\u0442\u0434\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u2014 \u0437\u0430\u0442\u0435\u043c\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 json.<\/p>\n<h4>Drupal.ajax<\/h4>\n<p>  \u0412 Drupal \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/>  \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0441\u044f \u043e\u043d \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 (\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 Form API \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e), \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<br \/>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">var settings = {url : myUrl}; var ajax = new Drupal.ajax(false, false, settings); ajax.eventResponse(ajax, {}); <\/code><\/pre>\n<p>  \u0422\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0443\u0436\u043d\u0430 \u0447\u0442\u043e\u0431\u044b \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441. \u0415\u0441\u043b\u0438 \u0435\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0430\u043d \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 JS-\u0441\u043e\u0431\u044b\u0442\u0438\u0435 settings.event (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e &#8216;mousedown&#8217;) \u043d\u0430\u0434 DOM\/jQuery \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 Drupal.ajax().<br \/>  \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0443 \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e.<br \/>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e Drupal.ajax \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435 misc\/ajax.js, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u0442\u043e <a href=\"http:\/\/javascript.ru\/tutorial\/object\/inheritance#nasledovanie-na-klassah-funkciya-extend\">\u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f<\/a> \u043e\u0442 Drupal.ajax, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 success callback), \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  \u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c \u043d\u0438\u0436\u0435 \u043f\u043e \u043a\u043e\u0434\u0443 (\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043f\u043e\u0437\u0436\u0435 ajax.js), \u0445\u043e\u0442\u044f \u044f \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u0438\u043d\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0432\u0441\u0435 \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0434\u043e\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f new Drupal.ajax, \u0438 \u0432\u0430\u043c \u0442\u0443\u0434\u0430 \u043d\u0435 \u043f\u043e\u0434\u043b\u0435\u0437\u0442\u044c (\u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0443\u0436\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f).<br \/>  \u0422\u0430\u043a \u0436\u0435 \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e Drupal.ajax \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0430\u0442\u044c POST, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 dataType \u0431\u0443\u0434\u0435\u0442 json. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0442\u043e \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c\/\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h4>JS-commands<\/h4>\n<p>  JS-\u043a\u043e\u043c\u0430\u043d\u0434\u044b \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u044b\u0445 \u0442\u0435\u043c, \u0447\u0442\u043e \u0444\u0430\u043a\u0442 \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 ajax-\u043e\u0442\u0432\u0435\u0442\u0430.<br \/>  \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0432, \u043a\u0430\u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u044e \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u0434\u043b\u044f ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0438\u0434\u0430:  <\/p>\n<pre><code class=\"php\">function your_module_ajax_menu_callback() {   \/\/ ...   $result = array(     '#type' =&gt; 'ajax',     '#commands' =&gt; array(       array(         'command' =&gt; $command_name,       ),     ),   );   return $result; } <\/code><\/pre>\n<p>  \u0413\u0434\u0435 $command_name \u2014 \u0438\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Drupal.ajax.prototype.commands.<br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 $result \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u043d\u0434\u0435\u0440-\u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043e\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0432 json-\u0434\u0430\u043d\u043d\u044b\u0435, \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 hook_menu, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043b\u0431\u0435\u043a\u0443, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 &#8216;delivery callback&#8217; \u2014 &#8216;ajax_deliver&#8217;:  <\/p>\n<pre><code class=\"php\">function your_module_menu() {   \/\/ ...   $items['ajax\/your-module\/path'] = array(     'title' =&gt; 'Get content by AJAX',     'page callback' =&gt; 'your_module_ajax_menu_callback',     'page arguments' =&gt; array(),     'access arguments' =&gt; array('access content'),     'type' =&gt; MENU_CALLBACK,     'delivery callback' =&gt; 'ajax_deliver',   );   return $items; } <\/code><\/pre>\n<p>  \u041e\u0442\u0432\u0435\u0442 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u043d\u043e \u043a\u0442\u043e \u0436\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043d\u0430\u0448\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b? \u0418 \u0442\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0442\u0440\u0435\u0442\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 Drupal.ajax.<br \/>  \u041e\u0442\u0441\u044b\u043b\u043a\u0430 ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a success \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0443\u0436\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d, \u043e\u043d \u043f\u0435\u0440\u0435\u0431\u0435\u0440\u0435\u0442 \u0432\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u0430, \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<br \/>  \u041e\u0431\u044b\u0447\u043d\u043e \u043c\u044b \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438:  <\/p>\n<pre><code class=\"javascript\">$('#somen-link').click(function () {   $.ajax({     type: 'GET',     url: myUrl,     dataType: 'html',     success: function (data) {       \/\/ Set up new content.       $('div.container').html(data);     }   }); }); <\/code><\/pre>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430, \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u044d\u0442\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">var ajax = new Drupal.ajax(false, '#somen-link', {url : myUrl}); ajax.eventResponse(ajax, {}); <\/code><\/pre>\n<p>  \u0418 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0432 \u043c\u0435\u043d\u044e \u043a\u043e\u043b\u0431\u0435\u043a\u0435 (\u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e ajax_deliver \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 delivery callback):  <\/p>\n<pre><code class=\"php\">$result = array('#type' =&gt; 'ajax'); $result['#commands'][] = ajax_command_insert('div.container', $html); return $result; <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0438 \u043d\u0430\u0448\u0435\u043c ajax \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043c\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 ajax_deliver() \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u0432 json, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u0432 Drupal.ajax.prototype.success \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>  \u0421\u043c\u044b\u0441\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 ajax_command_insert() \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 JS-\u043a\u043e\u043c\u0430\u043d\u0434\u044b.<br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438\u0437 \u043a\u043b\u044e\u0447\u0430 &#8216;data&#8217; \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0441 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u043c $selector:  <\/p>\n<pre><code class=\"php\">array(   'command' =&gt; 'insert',   'method' =&gt; NULL,   'selector' =&gt; $selector,   'data' =&gt; $html,   'settings' =&gt; $settings, ); <\/code><\/pre>\n<p>  \u0412 \u044f\u0434\u0440\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0440\u044f\u0434 ajax_command_* \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u0437 ajax.js.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f Drupal.ajax.prototype.commands:  <\/p>\n<pre><code class=\"javascript\">\/**  * Ajax delivery command to switch among tabs by ID.  *\/ Drupal.ajax.prototype.commands.gotoTab = function (ajax, response, status) {   \/\/ response.data is a value setted in 'data' key of command on PHP side.   if (response.data) {      \/\/ ...   } }; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0435\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0430 &#8216;command&#8217;, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0435\u0435 \u0438\u043c\u044f \u2014 gotoTab:  <\/p>\n<pre><code class=\"php\">$result['#commands'][] = array(    'command' =&gt; 'gotoTab', ); <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u043d\u0430\u0448\u0435\u0439 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u0430\u043a response.YOUR_KEY, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 response.selector \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 insert. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  \u0427\u0442\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0430\u0435\u0442?<br \/>  \u0412\u043e \u043f\u0435\u0440\u0432\u044b\u0445 \u0435\u0441\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 success \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<br \/>  \u0421\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u044f\u0434\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 ajax.js, \u0442\u0430\u043c \u0433\u0434\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Drupal.ajax.prototype.commands.<\/p>\n<p>  \u0412\u043e \u0432\u0442\u043e\u0440\u044b\u0445, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0432\u043e\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434, \u0430 \u0437\u0430\u0442\u0435\u043c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434 (\u0438\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u0442\u044c \u043a\u043e\u043c\u0443-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 hook_alter) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u043a\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/164443\/\"> http:\/\/habrahabr.ru\/post\/164443\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e \u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435 \u0448\u043b\u044e\u0442 ajax \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0440\u0443\u043a\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e $.ajax(), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 Drupal \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u044f\u0434\u0440\u0430, \u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e JS \u043a\u043e\u0434\u0430.<br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0432\u0435\u0449\u0430\u043c\u0438 \u043a\u0430\u043a delivery callback, Drupal.ajax \u0438 JS-commands.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-164443","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/164443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164443"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/164443\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}