<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ajax &#8212; ploshadka.net</title>
	<atom:link href="https://ploshadka.net/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>https://ploshadka.net</link>
	<description>Мир интернет технологий</description>
	<lastBuildDate>Thu, 27 Aug 2020 07:34:17 +0000</lastBuildDate>
	<language>ru-RU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1</generator>
	<item>
		<title>Svelte &#8212; кнопка автообновления</title>
		<link>https://ploshadka.net/svelte-knopka-avtoobnovlenija/</link>
					<comments>https://ploshadka.net/svelte-knopka-avtoobnovlenija/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sun, 10 Jan 2021 08:00:00 +0000</pubDate>
				<category><![CDATA[Svelte]]></category>
		<category><![CDATA[ajax]]></category>
		<guid isPermaLink="false">https://ploshadka.net/?p=6384</guid>

					<description><![CDATA[Пример кнопки с отчетом таймера на Svelte, после или в течении которого происходит какое-нибудь событие. Это событие обновляет страницу или подтягивает данные аяксом без обновления. В примере ниже, по кнопке запустить обновления, запускаются обновления и счетчик отчитывается до 0, после...]]></description>
										<content:encoded><![CDATA[<p>Пример кнопки с отчетом таймера на <strong>Svelte</strong>, после или в течении которого происходит какое-нибудь событие. Это событие обновляет страницу или подтягивает данные аяксом без обновления.<br />
<span id="more-6384"></span></p>
<p>В примере ниже, по кнопке запустить обновления, запускаются обновления и счетчик отчитывается до 0, после которого снова будет запущено обновление. И т.д. пока не отключить.</p>
<p><a href="https://ploshadka.net/wp-content/uploads/6384/update1.jpg" rel="lightbox-0"><img wpfc-lazyload-disable="true" decoding="async" loading="lazy" src="https://ploshadka.net/wp-content/uploads/6384/update1-600x321.jpg" alt="" width="400" height="170" class="aligncenter size-medium wp-image-6387" /></a></p>
<p><a href="https://ploshadka.net/wp-content/uploads/6384/update2.jpg" rel="lightbox-1"><img wpfc-lazyload-disable="true" decoding="async" loading="lazy" src="https://ploshadka.net/wp-content/uploads/6384/update2-600x304.jpg" alt="" width="400" height="170" class="aligncenter size-medium wp-image-6386" /></a></p>
<p>Первичное подключение функций svelte не связанных с таймером, но завязанных на нём: аякс запросы, которые подтягиваются на страницу.</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #FF0000;">import</span> <span style="color: #009900;">&#123;</span>onMount<span style="color: #009900;">&#125;</span> from <span style="color: #3366CC;">&quot;svelte&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; let updatedAtPortfolio<span style="color: #339933;">,</span> updatedAtPriceInPortfolio<span style="color: #339933;">,</span> updatedAtOperations<span style="color: #339933;">,</span> updatedAtPrices<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; onMount<span style="color: #009900;">&#40;</span>async <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; getDates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Получение дат обновления</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> getDates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; updatedAtPortfolio <span style="color: #339933;">=</span> getFetch<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'get-updated-at-portfolio/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; updatedAtPriceInPortfolio <span style="color: #339933;">=</span> getFetch<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'get-updated-at-price-in-portfolio/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; updatedAtOperations <span style="color: #339933;">=</span> getFetch<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'get-updated-at-operations/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; updatedAtPrices <span style="color: #339933;">=</span> getFetch<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'get-updated-at-prices/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> getUpdatedDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; getFetch<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'update-all-information/'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">then</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getDates<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">location</span>.<span style="color: #660066;">reload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>Непосредственно функции таймера в Svelte:</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp; &nbsp; let varSetInterval<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varSetTimeout<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer <span style="color: #339933;">=</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status <span style="color: #339933;">=</span> <span style="color: #3366CC;">'ВЫКЛ'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> setTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; timer <span style="color: #339933;">=</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; status <span style="color: #339933;">=</span> <span style="color: #3366CC;">'ВКЛ'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; document.<span style="color: #660066;">cookie</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'svelteLiveUpdate=1'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; varSetInterval <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>timer <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> timer<span style="color: #339933;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; varSetTimeout <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Запускаем обновление по окончанию таймера</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getUpdatedDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Сбрасывает таймер</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval<span style="color: #009900;">&#40;</span>varSetInterval<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearTimeout<span style="color: #009900;">&#40;</span>varSetTimeout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>getCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;svelteLiveUpdate&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'1'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; let stop <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> clickLiveReload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>getCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;svelteLiveUpdate&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'1'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Запускаем обновление при нажатии кнопки</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>stop<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getUpdatedDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stop <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.<span style="color: #660066;">cookie</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'svelteLiveUpdate=0'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval<span style="color: #009900;">&#40;</span>varSetInterval<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearTimeout<span style="color: #009900;">&#40;</span>varSetTimeout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer <span style="color: #339933;">=</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status <span style="color: #339933;">=</span> <span style="color: #3366CC;">'ВЫКЛ'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; setTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div>
<p>Таблица на скрине. Здесь при клике на кнопку срабатывает функция <strong>clickLiveReload</strong> из кода выше. Она же запускает обновление, сохраняет куки и включает/выключает таймер на svelte.</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;table table-links&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;body&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item link center&quot;</span> on:click<span style="color: #66cc66;">=</span><span style="color: #66cc66;">&#123;</span>clickLiveReload<span style="color: #66cc66;">&#125;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {#if timer === '-'}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;dic <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell&quot;</span>&gt;</span>Обновить и запустить автообновление<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>dic&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {:else}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;dic <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell&quot;</span>&gt;</span>Обновится через {timer} секунд<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>dic&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {/if}<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; {#await updatedAtPortfolio}<br />
&nbsp; &nbsp; &nbsp; &nbsp; {:then updatedAtPortfolio}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell name&quot;</span>&gt;</span>Портфель:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell date center&quot;</span>&gt;</span>{updatedAtPortfolio}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {/await}<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; {#await updatedAtPriceInPortfolio}<br />
&nbsp; &nbsp; &nbsp; &nbsp; {:then updatedAtPriceInPortfolio}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell name&quot;</span>&gt;</span>Тек. цены в портфеле:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell date center&quot;</span>&gt;</span>{updatedAtPriceInPortfolio}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {/await}<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; {#await updatedAtOperations}<br />
&nbsp; &nbsp; &nbsp; &nbsp; {:then updatedAtOperations}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell name&quot;</span>&gt;</span>Все операции:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell date center&quot;</span>&gt;</span>{updatedAtOperations}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {/await}<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; {#await updatedAtPrices}<br />
&nbsp; &nbsp; &nbsp; &nbsp; {:then updatedAtPrices}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell name&quot;</span>&gt;</span>Цены на {nameOfShare}:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cell date center&quot;</span>&gt;</span>{updatedAtPrices}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {/await}<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ploshadka.net/svelte-knopka-avtoobnovlenija/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Варианты выхода из скрипта php для ответа в ajax</title>
		<link>https://ploshadka.net/varianty-vykhoda-iz-skripta-php-dlja-otveta-v-ajax/</link>
					<comments>https://ploshadka.net/varianty-vykhoda-iz-skripta-php-dlja-otveta-v-ajax/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Wed, 24 Jun 2020 08:00:00 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[PHP примеры и разбор]]></category>
		<category><![CDATA[Основательные труды]]></category>
		<guid isPermaLink="false">https://ploshadka.net/?p=5757</guid>

					<description><![CDATA[Пример функции выхода из метода PHP для отправки ответа на ajax. Допустим есть метод: public function ajaxGetSomething&#40;&#41; &#123;&#125; В нём что-то делается и нам нужно выйти из него включив шаблон HMTL или просто передать значение. Например, так: include __DIR__ ....]]></description>
										<content:encoded><![CDATA[<p>Пример функции выхода из метода PHP для отправки ответа на ajax. <span id="more-5757"></span></p>
<p>Допустим есть метод:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ajaxGetSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></div></div>
<p>В нём что-то делается и нам нужно выйти из него включив шаблон HMTL или просто передать значение. Например, так:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #b1b100;">include</span> __DIR__ <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/get.php'</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Казалось бы, на js нам достаточно будет проверить ответ на то, что ответ не пустой.</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; method &nbsp;<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; url &nbsp; &nbsp; <span style="color: #339933;">:</span> ajax.<span style="color: #660066;">ajaxurl</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; data &nbsp; &nbsp;<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; action &nbsp; &nbsp; &nbsp;<span style="color: #339933;">:</span> <span style="color: #3366CC;">'some_action'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; success <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">length</span> <span style="color: #339933;">!==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<div class="highlight">Однако иногда такое приводит к ошибке. </p>
<p><strong>die()</strong> или <strong>die(0)</strong>, может вернуть <strong>не пустоту или 0</strong>, а <strong>строку</strong> с несколькими пустыми символами в первом случае и строку с несколькими пустыми символами и нулем в другом.</div>
<p>Можно конечно поставить в <strong>die(&#8216;end&#8217;)</strong> или <strong>die(0)</strong> и проверить в js на соответствие через поиск:</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">response.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span></div></div>
<p>Но это больше похоже костыль. Лучше поступить иначе и написать в методе php выход следующего рода:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'success'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'один из вариантов сообщения'</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/ob_start"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">include</span> __DIR__ <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/get.php'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ob_get_clean"><span style="color: #990000;">ob_get_clean</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <a href="http://www.php.net/json_encode"><span style="color: #990000;">json_encode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Тогда на стороне JS мы можем проверить есть ли в ответе статус <strong>success</strong>. И если он присутствует, то вывести одно, а в его отсутствии другое.</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">success</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
div1.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> response.<span style="color: #660066;">content</span><span style="color: #339933;">;</span><br />
div2.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> response.<span style="color: #660066;">message</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ploshadka.net/varianty-vykhoda-iz-skripta-php-dlja-otveta-v-ajax/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CSS анимация на JS ajax</title>
		<link>https://ploshadka.net/css-animacija-na-js-ajax/</link>
					<comments>https://ploshadka.net/css-animacija-na-js-ajax/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 19 Jun 2020 08:00:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ajax]]></category>
		<guid isPermaLink="false">https://ploshadka.net/?p=5747</guid>

					<description><![CDATA[Простой пример анимации на css. Примеры анимации можно найти здесь: https://daneden.github.io/animate.css/ Ниже пример, как сделать одну из любой анимации оттуда или вообще, чтобы все работало. HTML &#60;div class=&#34;message&#34;&#62; &#160; &#160; &#60;div class=&#34;js-message animated pulse&#34;&#62;&#60;/div&#62; &#60;/div&#62; Контейнер message нужен для обрамления...]]></description>
										<content:encoded><![CDATA[<p>Простой пример анимации на css. <span id="more-5747"></span></p>
<p>Примеры анимации можно найти здесь:<br />
<a href="https://daneden.github.io/animate.css/" rel="noopener noreferrer" target="_blank">https://daneden.github.io/animate.css/</a></p>
<p>Ниже пример, как сделать одну из любой анимации оттуда или вообще, чтобы все работало.</p>
<h2>HTML</h2>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;js-message animated pulse&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></div></div>
<p>Контейнер <strong>message</strong> нужен для обрамления анимации, чтобы внутри него можно было с ней делать, что душе захочется.</p>
<p><strong>js-message</strong> &#8212; класс, за который будем цепляться в JS.</p>
<p><strong>animated pulse</strong> &#8212; классы, которые описывают саму анимацию.</p>
<p>И еще у нас будет класс <strong>hidden</strong>, который буде вешаться и убираться через JS. Это создаст анимацию в уже присутствующих классах.</p>
<h2>SCSS</h2>
<div class="codecolorer-container css dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #6666ff;">.message</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #dc143c;">maroon</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; &nbsp; // Обязательно для анимации!<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6666ff;">.animated</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">animation-duration</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3s</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">animation-fill-mode</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #6666ff;">.pulse</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; -webkit-animation-name<span style="color: #00AA00;">:</span> pulse<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">animation-name</span><span style="color: #00AA00;">:</span> pulse<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #3F84D9; font-weight: bold;">@keyframes</span> pulse <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -webkit-transform<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">transform</span><span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #933;">50%</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -webkit-transform<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">transform</span><span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1.05</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; to <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -webkit-transform<span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">transform</span><span style="color: #00AA00;">:</span> <span style="color: #9932cc;">scale3d</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<h2>JS</h2>
<p><strong>Пример функции отправки в wordpress jquery ajax запроса на бэк</strong>. Анимация будет появляться при получении ответа с бэка.</p>
<p>Функцию максимально упростил, оставил самое нужное для наглядности.</p>
<p>Класс <strong>hidden</strong> мы навешиваем при нажатии на ссылку. А снимаем после прихода ответа. Тем самым происходит анимация.</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">function</span> increase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; let link <span style="color: #339933;">=</span> document.<span style="color: #660066;">querySelector</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.js-link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>link<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; let message <span style="color: #339933;">=</span> document.<span style="color: #660066;">querySelector</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.js-message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stop &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; link.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>stop<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; let current &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=</span> e.<span style="color: #660066;">target</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentClass <span style="color: #339933;">=</span> current.<span style="color: #660066;">classList</span>.<span style="color: #660066;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'js-link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>currentClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; message.<span style="color: #660066;">classList</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hidden'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; method &nbsp;<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url &nbsp; &nbsp; <span style="color: #339933;">:</span> ajax.<span style="color: #660066;">ajaxurl</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data &nbsp; &nbsp;<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'increase'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.<span style="color: #660066;">classList</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hidden'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stop <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ploshadka.net/css-animacija-na-js-ajax/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Как работает ajax в wordpress</title>
		<link>https://ploshadka.net/kak-rabotaet-ajax-v-wordpress/</link>
					<comments>https://ploshadka.net/kak-rabotaet-ajax-v-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Wed, 05 Jun 2019 08:00:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ajax]]></category>
		<guid isPermaLink="false">https://ploshadka.net/?p=5090</guid>

					<description><![CDATA[Краткое описание и пример работы ajax в wordpress. Определяем переменную ajaxurl для frontend: add_action('wp_enqueue_scripts', function(){ &#160; &#160; wp_localize_script( &#160; &#160; &#160; &#160; 'ploshadka', &#160; &#160; &#160; &#160; 'ajax', &#160; &#160; &#160; &#160; ['ajaxurl' =&#62; admin_url('admin-ajax.php')] &#160; &#160; ); }); Экшены...]]></description>
										<content:encoded><![CDATA[<p>Краткое описание и пример работы ajax в wordpress. <span id="more-5090"></span></p>
<p>Определяем переменную ajaxurl для frontend:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">add_action('wp_enqueue_scripts', function(){<br />
&nbsp; &nbsp; wp_localize_script(<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'ploshadka',<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'ajax',<br />
&nbsp; &nbsp; &nbsp; &nbsp; ['ajaxurl' =&gt; admin_url('admin-ajax.php')]<br />
&nbsp; &nbsp; );<br />
});</div></div>
<p>Экшены вызова PHP функции из JS:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">add_action('wp_ajax_name_action', 'actionFunctionPloshadka'); <br />
add_action('wp_ajax_nopriv_name_action', 'actionFunctionPloshadka');</div></div>
<p>Функция JS:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">jQuery.ajax({<br />
&nbsp; &nbsp; type: 'post',<br />
&nbsp; &nbsp; url: ajax.ajaxurl,<br />
&nbsp; &nbsp; data: {<br />
&nbsp; &nbsp; &nbsp; &nbsp; action: 'name_action',<br />
&nbsp; &nbsp; &nbsp; &nbsp; name: nameVar;<br />
&nbsp; &nbsp; },<br />
&nbsp; &nbsp; success: function (success) {<br />
&nbsp; &nbsp; }<br />
});</div></div>
<p>Вызываемая из ajax PHP функция:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">public static function actionFunctionPloshadka() <br />
{<br />
}</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ploshadka.net/kak-rabotaet-ajax-v-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Определение ошибок на ajax</title>
		<link>https://ploshadka.net/ajax-errors/</link>
					<comments>https://ploshadka.net/ajax-errors/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Mon, 02 Jul 2018 10:41:02 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">https://ploshadka.net/?p=4314</guid>

					<description><![CDATA[Как посмотреть какие ошибки показывается, когда ajax не выполняется правильным образом. Одна из причин почему на WordPress может не работать ajax, это когда он не разрешен незарегистрированным пользователям. Он будет вызвать ошибку 400 Bad Request. jQuery Для jQuery ошибки можно...]]></description>
										<content:encoded><![CDATA[<p>Как посмотреть какие ошибки показывается, когда ajax не выполняется правильным образом. <span id="more-4314"></span></p>
<p>Одна из причин почему на WordPress может не работать ajax, это когда он не разрешен незарегистрированным пользователям. Он будет вызвать ошибку <strong>400 Bad Request</strong>.</p>
<h2>jQuery</h2>
<p>Для jQuery ошибки можно увидеть так:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">error: function( xhr, textStatus ) {<br />
&nbsp; &nbsp; alert( [ xhr.status, textStatus ] );<br />
},</div></div>
<p>или так:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">error: function (e) {<br />
&nbsp; &nbsp; console.log(e);<br />
},</div></div>
<h2>JavaScript</h2>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(request.readyState === 4) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(request.status === 200) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(''Произошла ошибка при запросе: ' + &nbsp;request.status + ' ' + request.statusText);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div></div>
<p>Как вариант, можно посмотреть что именно выводится</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(request.readyState === 4) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(request.status === 200) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Произошла ошибка при запросе: ' + request.responseText);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ploshadka.net/ajax-errors/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
