<?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>Ambition Lab &#187; code snippet</title>
	<atom:link href="http://www.ambitionlab.com/tag/code-snippet/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ambitionlab.com</link>
	<description>Rajeev Singh</description>
	<lastBuildDate>Tue, 25 May 2010 21:28:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to check if a file exists using JQuery</title>
		<link>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06</link>
		<comments>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:54:11 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[code snippet]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=205</guid>
		<description><![CDATA[The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.
It&#8217;s also worth noting that a HEAD request also returns the content length and last modified [...]]]></description>
			<content:encoded><![CDATA[<p>The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.</p>
<p>It&#8217;s also worth noting that a HEAD request also returns the content length and last modified date, and that jQuery has an &#8220;ifModified&#8221; option for the .ajax function that returns a boolean value.</p>
<p>Quick code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'http://www.example.com/somefile.ext'</span><span style="color: #339933;">,</span>
    type<span style="color: #339933;">:</span><span style="color: #3366CC;">'HEAD'</span><span style="color: #339933;">,</span>
    error<span style="color: #339933;">:</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//do something depressing</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    success<span style="color: #339933;">:</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//do something cheerful :)</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Couldn&#8217;t be easier!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

