<?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>Блог на Венелин Кочев &#187; JavaScript</title>
	<atom:link href="http://cyberroot.net/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://cyberroot.net</link>
	<description></description>
	<lastBuildDate>Sun, 09 Oct 2011 07:56:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Използване на php функции в javascript</title>
		<link>http://cyberroot.net/2009/04/14/%d0%b8%d0%b7%d0%bf%d0%be%d0%bb%d0%b7%d0%b2%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-php-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d0%b8-%d0%b2-javascript/</link>
		<comments>http://cyberroot.net/2009/04/14/%d0%b8%d0%b7%d0%bf%d0%be%d0%bb%d0%b7%d0%b2%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-php-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d0%b8-%d0%b2-javascript/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 09:35:46 +0000</pubDate>
		<dc:creator>Venelin Kochev</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Интернет]]></category>
		<category><![CDATA[base64_decode]]></category>
		<category><![CDATA[base64_encode]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[javascript. function]]></category>

		<guid isPermaLink="false">http://cyberroot.org/?p=70</guid>
		<description><![CDATA[Мислили ли сте някога че възможно да използвате base64_encode / decode , count, explode, file_get_contents, fopen и много други в javascript? Е това вече е възможно с PHP.JS , а това е пълния списък на функциите.]]></description>
			<content:encoded><![CDATA[<p>Мислили ли сте някога че възможно да използвате <a target="_blank"href="http://bg2.php.net/manual/en/function.base64-encode.php">base64_encode</a> / <a target="_blank" href="http://bg2.php.net/manual/en/function.base64-decode.php">decode </a>, <a target="_blank" href="http://bg2.php.net/manual/en/function.count.php">count</a>, <a target="_blank" href="http://bg2.php.net/manual/en/function.explode.php">explode</a>, <a target="_blank" href="http://bg2.php.net/manual/en/function.file-get-contents.php">file_get_contents</a>, <a target="_blank" href="http://bg2.php.net/manual/en/function.fopen.php">fopen</a> и много други в javascript?<br />
Е това вече е възможно с <a target="_blank" href="http://phpjs.org/">PHP.JS</a> , а това е <a taget="_blank" href="http://phpjs.org/functions/index">пълния списък на функциите</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberroot.net/2009/04/14/%d0%b8%d0%b7%d0%bf%d0%be%d0%bb%d0%b7%d0%b2%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-php-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d0%b8-%d0%b2-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript addslashes/stripslashes</title>
		<link>http://cyberroot.net/2008/05/08/javascript-addslashes-stripslashes/</link>
		<comments>http://cyberroot.net/2008/05/08/javascript-addslashes-stripslashes/#comments</comments>
		<pubDate>Thu, 08 May 2008 12:45:42 +0000</pubDate>
		<dc:creator>Venelin Kochev</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[addslashes]]></category>
		<category><![CDATA[stripslashes]]></category>

		<guid isPermaLink="false">http://cyberroot.org/?p=13</guid>
		<description><![CDATA[Две алтернативи на функциите от PHP за JavaScript: function addslashes&#40;str&#41; &#123; str = str.replace&#40;/\'/g,'\\\''&#41;; str = str.replace&#40;/\&#34;/g,'\\&#34;'&#41;; str = str.replace&#40;/\\/g,'\\\\'&#41;; str = str.replace&#40;/\0/g,'\\0'&#41;; &#160; return str; &#125; &#160; function stripslashes&#40;str&#41; &#123; str = str.replace&#40;/\\'/g,'\''&#41;; str = str.replace&#40;/\\&#34;/g,'&#34;'&#41;; str = str.replace&#40;/\\\\/g,'\\'&#41;; str = str.replace&#40;/\\0/g,'\0'&#41;; &#160; return str; &#125;]]></description>
			<content:encoded><![CDATA[<p>Две алтернативи на функциите от PHP за JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addslashes<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\'/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\&quot;/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\\/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\0/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> stripslashes<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\\'/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\\&quot;/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\\\\/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\\0/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
]]></content:encoded>
			<wfw:commentRss>http://cyberroot.net/2008/05/08/javascript-addslashes-stripslashes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX кеширане в Internet Explorer</title>
		<link>http://cyberroot.net/2008/04/11/ie-ajax-cache/</link>
		<comments>http://cyberroot.net/2008/04/11/ie-ajax-cache/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 13:38:04 +0000</pubDate>
		<dc:creator>Venelin Kochev</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Cache]]></category>

		<guid isPermaLink="false">http://cyberroot.org/?p=10</guid>
		<description><![CDATA[Ако използвате GET метод, за изпращане на параметрите в AJAX скрипт, възможно е Internet Explorer да кешира резултата от първия request. За да се избегне това съществуват няколко &#8220;хак-а&#8221;. Номер 1. вместо: &#160; var url = 'getResult.php?username=test'; изплозвайте: &#160; var url = 'getResult.php?username=test' + '&#38;nocache=' + new Date&#40;&#41;.getTime&#40;&#41;; Това ще накара IE винаги да опреснява [...]]]></description>
			<content:encoded><![CDATA[<p>Ако използвате GET метод, за изпращане на параметрите в AJAX скрипт, възможно е Internet Explorer да кешира резултата от първия request.<br />
За да се избегне това съществуват няколко &#8220;хак-а&#8221;.</p>
<p>Номер 1.<br />
вместо:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'getResult.php?username=test'</span><span style="color: #339933;">;</span></pre></div></div>

<p>изплозвайте:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'getResult.php?username=test'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;nocache='</span> <span style="color: #339933;">+</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Това ще накара IE винаги да опреснява резултата от всяка заявка.</p>
<p>Номер 2.</p>
<p>В някои случаи помага и този вариант:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
Response.<span style="color: #660066;">CacheControl</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;no-cache&quot;</span><span style="color: #339933;">;</span>
Response.<span style="color: #660066;">AddHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Pragma&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Response.<span style="color: #660066;">Expires</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>Третия вариант е да използвате POST метод. <img src='http://cyberroot.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://cyberroot.net/2008/04/11/ie-ajax-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP redirect</title>
		<link>http://cyberroot.net/2008/04/03/php-redirect/</link>
		<comments>http://cyberroot.net/2008/04/03/php-redirect/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 10:16:20 +0000</pubDate>
		<dc:creator>Venelin Kochev</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://cyberroot.org/?p=8</guid>
		<description><![CDATA[Случвало ли ви се е да ползвате: header&#40;'Location: http://google.com/'&#41;; и в този момента да ви се отговори: Cannot modify header information &#8211; headers already sent by … и тогава се налага да го заменяте с meta redirect или някакъв redirect с javascript, а също и ob_start(); ob_end_flush(); което си е дразнещо. Ето една алтернатива: &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>Случвало ли ви се е да ползвате:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: http://google.com/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>и в този момента да ви се отговори:</p>
<blockquote><p>Cannot modify header information &#8211; headers already sent by …</p></blockquote>
<p>и тогава се налага да го заменяте с meta redirect или някакъв redirect с javascript, а също и ob_start(); ob_end_flush(); което си е дразнещо.</p>
<p>Ето една алтернатива:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> redirect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">headers_sent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;script type=&quot;text/javascript&quot;&gt;'</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'window.location.href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;;'</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/script&gt;'</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;noscript&gt;'</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;url='</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/noscript&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Тази функция проверява дали са изпратени header-ите, ако не са redirect-ва с PHP функцията “header”, ако са изпратени вече redirect-a се прави с javascript, а ако по някаква случайност потребителя няма support на javascript, redirect-a става с meta refresh на HTML</p>
<p>За тези които умуват още, ползва се така:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://google.com/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cyberroot.net/2008/04/03/php-redirect/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

