{"id":135291,"date":"2026-07-20T10:08:01","date_gmt":"2026-07-20T04:08:01","guid":{"rendered":"https:\/\/rcl-radio.ru\/?p=135291"},"modified":"2026-07-20T10:08:01","modified_gmt":"2026-07-20T04:08:01","slug":"fetch-api-%d0%b2-javascript-%d0%b4%d0%b5%d0%bb%d0%b0%d0%b5%d0%bc-http-%d0%b7%d0%b0%d0%bf%d1%80%d0%be%d1%81%d1%8b-%d0%b8-%d0%be%d0%b1%d1%80%d0%b0%d0%b1%d0%b0%d1%82%d1%8b%d0%b2%d0%b0%d0%b5","status":"publish","type":"post","link":"https:\/\/rcl-radio.ru\/?p=135291","title":{"rendered":"Fetch API \u0432 JavaScript: \u0434\u0435\u043b\u0430\u0435\u043c HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u044b (JavaScript)"},"content":{"rendered":"<p>Fetch API\u00a0\u2014\u00a0\u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u0435\u043b\u0430\u0442\u044c HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438: \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0448\u044c <code class=\"CodeInlined\">fetch()<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0448\u044c URL \u0438 (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0448\u044c \u043f\u0440\u043e\u043c\u0438\u0441 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u0414\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0448\u044c \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 (JSON, \u0442\u0435\u043a\u0441\u0442, Blob \u0438 \u0442.\u200a\u0434.) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0448\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<hr \/>\n<h2>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 GET\u2011\u0437\u0430\u043f\u0440\u043e\u0441<\/h2>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/api.example.com\/data'<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>response =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">!<\/span>response.<span style=\"color: #006600;\">ok<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n      <span style=\"color: #0066cc;\">throw<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #0066cc;\">Error<\/span><span style=\"color: #66cc66;\">(<\/span>`\u041e\u0448\u0438\u0431\u043a\u0430 HTTP: $<span style=\"color: #66cc66;\">{<\/span>response.<span style=\"color: #0066cc;\">status<\/span><span style=\"color: #66cc66;\">}<\/span>`<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n    <span style=\"color: #b1b100;\">return<\/span> response.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>; <span style=\"color: #808080; font-style: italic;\">\/\/ \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u0435\u043b\u043e \u043a\u0430\u043a JSON<\/span>\r\n  <span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> console.<span style=\"color: #0066cc;\">log<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>err =<span style=\"color: #66cc66;\">&gt;<\/span> console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430:'<\/span>, err<span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0427\u0442\u043e \u0442\u0443\u0442 \u0432\u0430\u0436\u043d\u043e:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.ok<\/code>\u00a0\u2014\u00a0\u044d\u0442\u043e <code class=\"CodeInlined\">true<\/code>, \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 200\u2013299. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442\u00a0\u2014\u00a0\u0437\u043d\u0430\u0447\u0438\u0442, \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0443\u043b \u043e\u0448\u0438\u0431\u043a\u0443 (404, 500 \u0438 \u0442.\u200a\u043f.), \u0438 \u0435\u0451 \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.json()<\/code>\u00a0\u2014\u00a0\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043f\u0430\u0440\u0441\u0438\u0442 JSON. \u041e\u043d \u0442\u043e\u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">.catch()<\/code> \u043b\u043e\u0432\u0438\u0442 \u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (\u043d\u0435\u0442 \u0441\u0435\u0442\u0438, \u0442\u0430\u0439\u043c\u0430\u0443\u0442), \u0438 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u044b \u0441\u0430\u043c \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u043b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 <code class=\"CodeInlined\">!response.ok<\/code>).<\/li>\n<\/ul>\n<hr \/>\n<h2>GET \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 (query string)<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code class=\"CodeInlined\">?page=1&amp;limit=10<\/code>), \u043b\u0443\u0447\u0448\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <code class=\"CodeInlined\">URLSearchParams<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<p>&lt;<\/p>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">const params = <span style=\"color: #000000; font-weight: bold;\">new<\/span> URLSearchParams<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">{<\/span>\r\n  page: <span style=\"color: #ff0000;\">'1'<\/span>,\r\n  limit: <span style=\"color: #ff0000;\">'10'<\/span>,\r\n  search: <span style=\"color: #ff0000;\">'hello'<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\nfetch<span style=\"color: #66cc66;\">(<\/span>`https:<span style=\"color: #808080; font-style: italic;\">\/\/api.example.com\/items?${params}`)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>r =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">!<\/span>r.<span style=\"color: #006600;\">ok<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #0066cc;\">throw<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #0066cc;\">Error<\/span><span style=\"color: #66cc66;\">(<\/span>`HTTP $<span style=\"color: #66cc66;\">{<\/span>r.<span style=\"color: #0066cc;\">status<\/span><span style=\"color: #66cc66;\">}<\/span>`<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #b1b100;\">return<\/span> r.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> console.<span style=\"color: #0066cc;\">log<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0422\u0430\u043a \u043c\u0435\u043d\u044c\u0448\u0435 \u0448\u0430\u043d\u0441\u043e\u0432 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<hr \/>\n<h2>POST \u0441 JSON\u2011\u0442\u0435\u043b\u043e\u043c<\/h2>\n<p>\u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 JSON:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">const payload = <span style=\"color: #66cc66;\">{<\/span> <span style=\"color: #0066cc;\">name<\/span>: <span style=\"color: #ff0000;\">'Alice'<\/span>, age: <span style=\"color: #cc66cc;\">30<\/span> <span style=\"color: #66cc66;\">}<\/span>;\r\n\u00a0\r\nfetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/api.example.com\/users'<\/span>, <span style=\"color: #66cc66;\">{<\/span>\r\n  method: <span style=\"color: #ff0000;\">'POST'<\/span>,\r\n  headers: <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #ff0000;\">'Content-Type'<\/span>: <span style=\"color: #ff0000;\">'application\/json'<\/span>\r\n  <span style=\"color: #66cc66;\">}<\/span>,\r\n  body: JSON.<span style=\"color: #006600;\">stringify<\/span><span style=\"color: #66cc66;\">(<\/span>payload<span style=\"color: #66cc66;\">)<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>r =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">!<\/span>r.<span style=\"color: #006600;\">ok<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #0066cc;\">throw<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #0066cc;\">Error<\/span><span style=\"color: #66cc66;\">(<\/span>`HTTP $<span style=\"color: #66cc66;\">{<\/span>r.<span style=\"color: #0066cc;\">status<\/span><span style=\"color: #66cc66;\">}<\/span>`<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #b1b100;\">return<\/span> r.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> console.<span style=\"color: #0066cc;\">log<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u0421\u043e\u0437\u0434\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c:'<\/span>, <span style=\"color: #0066cc;\">data<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0412\u0430\u0436\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c <code class=\"CodeInlined\">Content-Type: application\/json<\/code>.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (<code class=\"CodeInlined\">body<\/code>) \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0439\u00a0\u2014\u00a0\u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code class=\"CodeInlined\">JSON.stringify<\/code>.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c JSON \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430<\/h2>\n<p><code class=\"CodeInlined\">fetch<\/code> \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 \u0442\u0435\u043b\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0422\u044b \u0441\u0430\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0448\u044c, \u043a\u0430\u043a \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u044c:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.text()<\/code>\u00a0\u2014\u00a0\u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.json()<\/code>\u00a0\u2014\u00a0JSON (\u0441\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439).<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.blob()<\/code>\u00a0\u2014\u00a0\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u0444\u0430\u0439\u043b\u044b).<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">response.arrayBuffer()<\/code>\u00a0\u2014\u00a0\u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/example.com\/page.html'<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>r =<span style=\"color: #66cc66;\">&gt;<\/span> r.<span style=\"color: #0066cc;\">text<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">html<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> console.<span style=\"color: #0066cc;\">log<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">html<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u043e\u0439 (Blob \u2192 URL):<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/example.com\/image.png'<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>r =<span style=\"color: #66cc66;\">&gt;<\/span> r.<span style=\"color: #006600;\">blob<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>blob =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    const <span style=\"color: #0066cc;\">url<\/span> = <span style=\"color: #0066cc;\">URL<\/span>.<span style=\"color: #006600;\">createObjectURL<\/span><span style=\"color: #66cc66;\">(<\/span>blob<span style=\"color: #66cc66;\">)<\/span>;\r\n    document.<span style=\"color: #006600;\">querySelector<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'img'<\/span><span style=\"color: #66cc66;\">)<\/span>.<span style=\"color: #006600;\">src<\/span> = <span style=\"color: #0066cc;\">url<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  .<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h2>async\/await: \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0441\u0442\u0438\u043b\u044c<\/h2>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0438 <code class=\"CodeInlined\">.then()<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code class=\"CodeInlined\">async\/await<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">async <span style=\"color: #000000; font-weight: bold;\">function<\/span> getData<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n  <span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    const response = await fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/api.example.com\/data'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">!<\/span>response.<span style=\"color: #006600;\">ok<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n      <span style=\"color: #0066cc;\">throw<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #0066cc;\">Error<\/span><span style=\"color: #66cc66;\">(<\/span>`HTTP $<span style=\"color: #66cc66;\">{<\/span>response.<span style=\"color: #0066cc;\">status<\/span><span style=\"color: #66cc66;\">}<\/span>`<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    const <span style=\"color: #0066cc;\">data<\/span> = await response.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    console.<span style=\"color: #0066cc;\">log<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>err<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430:'<\/span>, err<span style=\"color: #66cc66;\">)<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\ngetData<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u043f\u043e\u0442\u043e\u043c \u0440\u0430\u0437\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<hr \/>\n<h2>\u0427\u0430\u0441\u0442\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0433\u0434\u0435 \u00ab\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f\u00bb<\/h2>\n<ol>\n<li data-value=\"1.\" data-shift=\"1\"><strong>\u0417\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c <code class=\"CodeInlined\">response.ok<\/code><\/strong><br \/>\nFetch \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u043c \u043b\u044e\u0431\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0434\u0430\u0436\u0435 404 \u0438 500. \u0415\u0441\u043b\u0438 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c <code class=\"CodeInlined\">ok<\/code>, \u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0448\u044c \u043f\u0440\u043e\u043c\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u00ab\u0443\u0441\u043f\u0435\u0448\u0435\u043d\u00bb, \u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438\u00a0\u2014\u00a0\u043e\u0448\u0438\u0431\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/li>\n<li data-value=\"2.\" data-shift=\"1\"><strong>\u041f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0435\u0437 <code class=\"CodeInlined\">await<\/code> \u0438\u043b\u0438 <code class=\"CodeInlined\">.then()<\/code><\/strong><br \/>\n<code class=\"CodeInlined\">response.json()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441. \u041d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code class=\"CodeInlined\">const data = response.json();<\/code> \u0438 \u0441\u0440\u0430\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code class=\"CodeInlined\">data<\/code>. \u041d\u0443\u0436\u043d\u043e \u043b\u0438\u0431\u043e <code class=\"CodeInlined\">await response.json()<\/code>, \u043b\u0438\u0431\u043e <code class=\"CodeInlined\">.then(json =&gt; ...)<\/code>.<\/li>\n<li data-value=\"3.\" data-shift=\"1\"><strong>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 <code class=\"CodeInlined\">Content-Type<\/code> \u0438\u043b\u0438 \u0437\u0430\u0431\u044b\u043b\u0438 <code class=\"CodeInlined\">JSON.stringify<\/code><\/strong><br \/>\n\u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c JSON \u0431\u0435\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code class=\"CodeInlined\">Content-Type: application\/json<\/code>, \u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442. \u0415\u0441\u043b\u0438 \u0437\u0430\u0431\u044b\u0442\u044c <code class=\"CodeInlined\">stringify<\/code>, \u0442\u0435\u043b\u043e \u0443\u0439\u0434\u0451\u0442 \u043a\u0430\u043a <code class=\"CodeInlined\">[object Object]<\/code>\u00a0\u2014\u00a0\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c.<\/li>\n<li data-value=\"4.\" data-shift=\"1\"><strong>CORS\u2011\u043e\u0448\u0438\u0431\u043a\u0438<\/strong><br \/>\n\u0415\u0441\u043b\u0438 \u0434\u0435\u043b\u0430\u0435\u0448\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043e\u043c\u0435\u043d, \u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 CORS, \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442. \u042d\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u0430\u043a CORS\u2011\u043e\u0448\u0438\u0431\u043a\u0430. \u0422\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430: \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438.<\/li>\n<li data-value=\"5.\" data-shift=\"1\"><strong>\u041d\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a<\/strong><br \/>\n\u0421\u0435\u0442\u0435\u0432\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (\u043d\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430, \u0442\u0430\u0439\u043c\u0430\u0443\u0442, DNS) \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code class=\"CodeInlined\">.catch()<\/code> \u0438\u043b\u0438 \u0432 <code class=\"CodeInlined\">try\/catch<\/code> \u043f\u0440\u0438 <code class=\"CodeInlined\">await<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0435 \u043b\u043e\u0432\u0438\u0442\u044c\u00a0\u2014\u00a0\u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f\u00bb \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u043d\u043e.<\/li>\n<\/ol>\n<hr \/>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440: \u0444\u043e\u0440\u043c\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u043e\u0440\u043c\u0430:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">html<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #66cc66;\">&lt;<\/span>form id=<span style=\"color: #ff0000;\">\"userForm\"<\/span><span style=\"color: #66cc66;\">&gt;<\/span>\r\n  <span style=\"color: #66cc66;\">&lt;<\/span>input <span style=\"color: #0066cc;\">name<\/span>=<span style=\"color: #ff0000;\">\"name\"<\/span> placeholder=<span style=\"color: #ff0000;\">\"\u0418\u043c\u044f\"<\/span> required<span style=\"color: #66cc66;\">&gt;<\/span>\r\n  <span style=\"color: #66cc66;\">&lt;<\/span><span style=\"color: #0066cc;\">button<\/span> <span style=\"color: #0066cc;\">type<\/span>=<span style=\"color: #ff0000;\">\"submit\"<\/span><span style=\"color: #66cc66;\">&gt;<\/span>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c<span style=\"color: #66cc66;\">&lt;\/<\/span>button<span style=\"color: #66cc66;\">&gt;<\/span>\r\n<span style=\"color: #66cc66;\">&lt;\/<\/span>form<span style=\"color: #66cc66;\">&gt;<\/span>\r\n<span style=\"color: #66cc66;\">&lt;<\/span>div id=<span style=\"color: #ff0000;\">\"message\"<\/span><span style=\"color: #66cc66;\">&gt;&lt;\/<\/span>div<span style=\"color: #66cc66;\">&gt;<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>JS:<\/p>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">document.<span style=\"color: #006600;\">getElementById<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'userForm'<\/span><span style=\"color: #66cc66;\">)<\/span>.<span style=\"color: #006600;\">addEventListener<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'submit'<\/span>, async <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">e<\/span><span style=\"color: #66cc66;\">)<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n  <span style=\"color: #0066cc;\">e<\/span>.<span style=\"color: #006600;\">preventDefault<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n  const form = <span style=\"color: #0066cc;\">e<\/span>.<span style=\"color: #0066cc;\">target<\/span>;\r\n  const messageBox = document.<span style=\"color: #006600;\">getElementById<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'message'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n  messageBox.<span style=\"color: #006600;\">textContent<\/span> = <span style=\"color: #ff0000;\">''<\/span>;\r\n\u00a0\r\n  const <span style=\"color: #0066cc;\">data<\/span> = <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #0066cc;\">name<\/span>: form.<span style=\"color: #0066cc;\">name<\/span>.<span style=\"color: #006600;\">value<\/span>.<span style=\"color: #006600;\">trim<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n  <span style=\"color: #66cc66;\">}<\/span>;\r\n\u00a0\r\n  <span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    const res = await fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\/api\/users'<\/span>, <span style=\"color: #66cc66;\">{<\/span>\r\n      method: <span style=\"color: #ff0000;\">'POST'<\/span>,\r\n      headers: <span style=\"color: #66cc66;\">{<\/span> <span style=\"color: #ff0000;\">'Content-Type'<\/span>: <span style=\"color: #ff0000;\">'application\/json'<\/span> <span style=\"color: #66cc66;\">}<\/span>,\r\n      body: JSON.<span style=\"color: #006600;\">stringify<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">data<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n    <span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">!<\/span>res.<span style=\"color: #006600;\">ok<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n      const errData = await res.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>.<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">{<\/span><span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n      <span style=\"color: #0066cc;\">throw<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #0066cc;\">Error<\/span><span style=\"color: #66cc66;\">(<\/span>errData.<span style=\"color: #0066cc;\">message<\/span> <span style=\"color: #66cc66;\">||<\/span> `\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430: $<span style=\"color: #66cc66;\">{<\/span>res.<span style=\"color: #0066cc;\">status<\/span><span style=\"color: #66cc66;\">}<\/span>`<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    const result = await res.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    messageBox.<span style=\"color: #006600;\">textContent<\/span> = <span style=\"color: #ff0000;\">'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u043d: '<\/span> + result.<span style=\"color: #0066cc;\">name<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>err<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    messageBox.<span style=\"color: #006600;\">textContent<\/span> = <span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430: '<\/span> + err.<span style=\"color: #0066cc;\">message<\/span>;\r\n  <span style=\"color: #66cc66;\">}<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u041e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b (<code class=\"CodeInlined\">preventDefault<\/code>).<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c JSON.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <code class=\"CodeInlined\">ok<\/code>, \u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u0437 \u0442\u0435\u043b\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043e\u0432\u0435\u0442 \u0434\u043b\u044f PunBB \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0442\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0448\u044c PunBB \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u042f\u043d\u0434\u0435\u043a\u0441\u043e\u043c) \u0438 \u0434\u0435\u043b\u0430\u0435\u0448\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u0414\u0435\u0440\u0436\u0438 URL API \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u0432\u0435\u0442\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 CORS.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0414\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0443\u043a\u0438 \u0438\u043b\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code class=\"CodeInlined\">Authorization: Bearer ...<\/code>). \u041a\u0443\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 <code class=\"CodeInlined\">credentials: 'include'<\/code> \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u0443\u043a\u0430\u043c\u0438:<\/li>\n<\/ul>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">js<\/div>\n<pre class=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'https:\/\/api.example.com\/profile'<\/span>, <span style=\"color: #66cc66;\">{<\/span>\r\n  credentials: <span style=\"color: #ff0000;\">'include'<\/span> <span style=\"color: #808080; font-style: italic;\">\/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0443\u043a\u0438 \u0434\u043e\u043c\u0435\u043d\u0430<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n.<span style=\"color: #006600;\">then<\/span><span style=\"color: #66cc66;\">(<\/span>r =<span style=\"color: #66cc66;\">&gt;<\/span> r.<span style=\"color: #006600;\">json<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n.<span style=\"color: #0066cc;\">catch<\/span><span style=\"color: #66cc66;\">(<\/span>console.<span style=\"color: #0066cc;\">error<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0411\u0435\u0437 <code class=\"CodeInlined\">credentials: 'include'<\/code> \u043a\u0443\u043a\u0438 \u043d\u0435 \u0443\u0439\u0434\u0443\u0442\u00a0\u2014\u00a0\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fetch API\u00a0\u2014\u00a0\u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u0435\u043b\u0430\u0442\u044c HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438: \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0448\u044c fetch(), \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0448\u044c URL \u0438 (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0448\u044c \u043f\u0440\u043e\u043c\u0438\u0441 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u0414\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0448\u044c \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 (JSON, \u0442\u0435\u043a\u0441\u0442, Blob \u0438 \u0442.\u200a\u0434.) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0448\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 GET\u2011\u0437\u0430\u043f\u0440\u043e\u0441 \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441: js fetch(&#8216;https:\/\/api.example.com\/data&#8217;) .then(response =&gt; { if (!response.ok) { throw new Error(`\u041e\u0448\u0438\u0431\u043a\u0430 HTTP: ${response.status}`); [&hellip;]<\/p>\n","protected":false},"author":9194254,"featured_media":135292,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[463],"tags":[],"class_list":["post-135291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"views":10,"_links":{"self":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/users\/9194254"}],"replies":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135291"}],"version-history":[{"count":1,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135291\/revisions"}],"predecessor-version":[{"id":135293,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135291\/revisions\/135293"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/135292"}],"wp:attachment":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}