<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: AJAX for idiots.</title>
	<link>http://ask.metafilter.com/35793/AJAX-for-idiots/</link>
	<description>Comments on Ask MetaFilter post AJAX for idiots.</description>
	<pubDate>Wed, 05 Apr 2006 15:59:51 -0800</pubDate>
	<lastBuildDate>Wed, 05 Apr 2006 15:59:51 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: AJAX for idiots.</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots</link>	
		<description>Stupid web development question about updating a database on a mouse click without re-loading the page (AJAX required?) &lt;br /&gt;&lt;br /&gt; I&apos;ve taken it upon myself to learn PHP and MySQL for a very basic website I want to build.  Basically, I have a database with a bunch of text entries and I want the site to dump them out based on various sorting or restrictions.  Simple enough.&lt;br&gt;
&lt;br&gt;
The part I need help with is that I want to give users a way to &quot;rate&quot; each item, so next to each line in the list there is a little thumbs up icon or star or something.  I need a way for a user to click on the icon and have it update the &quot;score&quot; of that icon in the MySQL DB without refreshing the page or taking them to a different page.  This is probably pretty simple to do, but I don&apos;t really know where to begin...Can I do this with pure JavaScript?  Any good code templates for this sort of thing?  Do I have to learn AJAX-y techniques?&lt;br&gt;
&lt;br&gt;
As an example, think about the gMail &quot;star&quot; thing.  When you click on the star, it fills in, and nothing else happens.  More importantly, that message gets permanently marked as starred.  That&apos;s what I want to happen!</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.35793</guid>
		<pubDate>Wed, 05 Apr 2006 15:54:51 -0800</pubDate>
		<dc:creator>TunnelArmr</dc:creator>
		
			<category>mysql</category>
		
			<category>webdevelopment</category>
		
	</item> <item>
		<title>By: y6y6y6</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556413</link>	
		<description>Thinking out loud here....... You can store the data using Javascript and then have it processed onUnLoad. So it&apos;s going to another page to process, but that&apos;s transparent to the user.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556413</guid>
		<pubDate>Wed, 05 Apr 2006 15:59:51 -0800</pubDate>
		<dc:creator>y6y6y6</dc:creator>
	</item><item>
		<title>By: frufry</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556423</link>	
		<description>AJAX is a perfectly decent solution, if you want to go that route.&lt;br&gt;
You could also bury a little form with a post in little IFrames, for each rating element.  The post would happen inside the IFrame, but the outer window would stay the same.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556423</guid>
		<pubDate>Wed, 05 Apr 2006 16:09:56 -0800</pubDate>
		<dc:creator>frufry</dc:creator>
	</item><item>
		<title>By: AmbroseChapel</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556426</link>	
		<description>It certainly is possible to do it via the temporary JavaScript storage and the onUnload() handler, but Google is probably doing it via AJAX. Don&apos;t make me look at their code, please!&lt;br&gt;
&lt;br&gt;
AJAX is very simple in principle. &lt;br&gt;
&lt;br&gt;
It&apos;s just like every other request to a server, except that as you say, the user doesn&apos;t see it happen. The request goes to a server, the server replies with some XML, and you process the XML.&lt;br&gt;
&lt;br&gt;
In your case you&apos;d make an &quot;update my database with this score for this user and this item&quot; request, via a javascript: URL or an onClick event, and the server would reply, if all went well, with some minimal XML that would mean &quot;it worked&quot; ... or something would go wrong in which case you&apos;d have to handle the error, of course.&lt;br&gt;
&lt;br&gt;
There&apos;s a little demonstration of how XHTTPRequests are used with iTunes &lt;a href=&quot;http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/example.html&quot;&gt;here&lt;/a&gt; that might give you a start.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556426</guid>
		<pubDate>Wed, 05 Apr 2006 16:11:59 -0800</pubDate>
		<dc:creator>AmbroseChapel</dc:creator>
	</item><item>
		<title>By: TunnelArmr</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556427</link>	
		<description>The reason I&apos;m concerned about doing it with AJAX is that I know nothing about it, and from the limited info I have seen, it would be a lot to learn for one minor function.&lt;br&gt;
&lt;br&gt;
y6y6y6, that Javascript solution would be nice, but won&apos;t it then not be recorded if they close the browser window straightaway instead of continuing on to another page?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556427</guid>
		<pubDate>Wed, 05 Apr 2006 16:12:37 -0800</pubDate>
		<dc:creator>TunnelArmr</dc:creator>
	</item><item>
		<title>By: jellicle</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556428</link>	
		<description>You can play around with &lt;a href=&quot;http://www.masuga.com/thelab/ajaxrate/&quot;&gt;this one&lt;/a&gt; or &lt;a href=&quot;http://slim.climaxdesigns.com/tutorial.php?section=slim&amp;id=3&quot;&gt;this one&lt;/a&gt; and see how they work.&lt;br&gt;
&lt;br&gt;
Ajax is a bit of an advanced topic if you&apos;re just learning PHP, though.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556428</guid>
		<pubDate>Wed, 05 Apr 2006 16:14:13 -0800</pubDate>
		<dc:creator>jellicle</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556441</link>	
		<description>You don&apos;t need to learn the details of XMLHttpRequest if you use either the &lt;a href=&quot;http://dojotoolkit.org/&quot;&gt;Dojo&lt;/a&gt; or the &lt;a href=&quot;http://prototype.conio.net/&quot;&gt;Prototype&lt;/a&gt; Javascript libraries.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556441</guid>
		<pubDate>Wed, 05 Apr 2006 16:31:36 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: potch</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556446</link>	
		<description>I second the Prototype Library. After using it to design a number of small interactive web apps, It makes Ajax as simple as calling the functions of a pre-created &lt;code&gt;Ajax&lt;/code&gt; object. Very simple, very easy on the individual who wants none of the nitty gritty.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556446</guid>
		<pubDate>Wed, 05 Apr 2006 16:38:45 -0800</pubDate>
		<dc:creator>potch</dc:creator>
	</item><item>
		<title>By: nielm</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556451</link>	
		<description>no need to go Ajax... use javascript to asynchronously load an image where the URL of the image is the vote-processing (or whatever) script...&lt;br&gt;
(&lt;a href=&quot;http://ask.metafilter.com/mefi/34210#534004&quot;&gt;as posted in a recent AskMefi answer &lt;/a&gt;)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556451</guid>
		<pubDate>Wed, 05 Apr 2006 16:40:29 -0800</pubDate>
		<dc:creator>nielm</dc:creator>
	</item><item>
		<title>By: ph00dz</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556471</link>	
		<description>Ajax isn&apos;t nearly as scary as you might think... check out the &lt;a href=&quot;http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html&quot;&gt;30 Second AJAX Tutorial&lt;/a&gt; by Rasmus Leidorf, creator of PHP. He lays it out in a very, very simple way.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556471</guid>
		<pubDate>Wed, 05 Apr 2006 16:56:23 -0800</pubDate>
		<dc:creator>ph00dz</dc:creator>
	</item><item>
		<title>By: the jam</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556719</link>	
		<description>AJAX sounds like what you want. If you&apos;re worried about things being too complicated, it don&apos;t get much simpler than &lt;a href=&quot;http://xkr.us/code/javascript/XHConn/&quot;&gt;XHConn&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556719</guid>
		<pubDate>Wed, 05 Apr 2006 21:09:58 -0800</pubDate>
		<dc:creator>the jam</dc:creator>
	</item><item>
		<title>By: Civil_Disobedient</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556779</link>	
		<description>Here&apos;s the basics (all snippets, but should be enough to get you started):&lt;br&gt;
&lt;br&gt;
Stars (right-click, save-as), or make your own:&lt;br&gt;
off: &lt;img src=&quot;http://www.sardegna.com/img/body/star/1_off.gif&quot;&gt; on: &lt;img src=&quot;http://www.sardegna.com/img/body/star/1_on.gif&quot;&gt;&lt;br&gt;
&lt;br&gt;
Code Snippets:&lt;br&gt;
&amp;lt;script&amp;gt;&lt;br&gt;
function updateStar(id) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var imgsrc = (document.getElementById(id).src == &quot;star_off.gif&quot;) ? &quot;star_on.gif&quot; : &quot;star_off.gif&quot;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var sendId = id.split(&apos;_&apos;)[1];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var sendStar = (imgsrc == &quot;star_off.gif&quot;) ? false : true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var objXml = new XMLHttpRequest();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var datasource = &quot;changestar.php&quot;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;var params = &quot;id=&quot; + sendId + &quot;&amp;amp;star=&quot; + sendStar;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;objXml.open(&quot;GET&quot;, datasource + &quot;?&quot; + params, true);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;objXml.onreadystatechange=function() {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ((objXml.readyState==4) &amp;amp;&amp;amp; (objXml.status==200)) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;alert(&apos;status changed.&apos;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;objXml.send(null);&lt;br&gt;
}&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
...&lt;br&gt;
&amp;lt;table&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Atom Heart Mother&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;img id=&quot;album_24123&quot; src=&quot;star_off.gif&quot; onclick=&quot;updateStar(this.id)&quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Dark Side of the Moon&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;img id=&quot;album_42312&quot; src=&quot;star_off.gif&quot; onclick=&quot;updateStar(this.id)&quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Wish You Were Here&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;img id=&quot;album_13534&quot; src=&quot;star_off.gif&quot; onclick=&quot;updateStar(this.id)&quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;The Wall&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;img id=&quot;album_82322&quot; src=&quot;star_off.gif&quot; onclick=&quot;updateStar(this.id)&quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br&gt;
&amp;lt;/table&amp;gt;&lt;br&gt;
...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556779</guid>
		<pubDate>Wed, 05 Apr 2006 22:19:17 -0800</pubDate>
		<dc:creator>Civil_Disobedient</dc:creator>
	</item><item>
		<title>By: Civil_Disobedient</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556787</link>	
		<description>Forgot to mention:&lt;br&gt;
&lt;br&gt;
In the above code, the script &quot;changestar.php&quot; takes two arguments: the first is the ID of the album to change, the second is the &quot;starred&quot; status (true/false).&lt;br&gt;
&lt;br&gt;
So, for example, the script could generate an SQL query like this:&lt;br&gt;
&lt;br&gt;
idFromGET = (retrieve the id variable in the GET variables)&lt;br&gt;
starFromGET = (retrieve the starred status from the GET variables)&lt;br&gt;
&lt;br&gt;
String sqlquery = &quot;UPDATE table_albums SET col_star =&quot; + starFromGET + &quot; WHERE col_id = &quot; + idFromGET;&lt;br&gt;
&lt;br&gt;
Naturally, if something like this is exposed to the &quot;masses&quot; (i.e., it&apos;s on the internet) you&apos;d want to validate the shit out of any GET variables before creating a query string out of them.&lt;br&gt;
&lt;br&gt;
If any or all of this is over your head, let me know and I&apos;ll try and help.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556787</guid>
		<pubDate>Wed, 05 Apr 2006 22:27:35 -0800</pubDate>
		<dc:creator>Civil_Disobedient</dc:creator>
	</item><item>
		<title>By: Sharcho</title>
		<link>http://ask.metafilter.com/35793/AJAX-for-idiots#556877</link>	
		<description>I&apos;ve spent the entire day evaluating the &lt;a href=&quot;http://ajaxpatterns.org/PHP_Ajax_Frameworks&quot;&gt;different AJAX libraries for PHP&lt;/a&gt;, and &lt;a href=&quot;http://www.xajaxproject.org/&quot;&gt;xajax&lt;/a&gt; seems the best (supports Unicode, actively developed, full featured, well documented, simple to use, developer community, works with all major browsers). &lt;a href=&quot;http://www.metz.se/tinyajax/index.php&quot;&gt;TinyAjax&lt;/a&gt; is also a worthy alternative, but not as good IMHO.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.35793-556877</guid>
		<pubDate>Thu, 06 Apr 2006 03:13:24 -0800</pubDate>
		<dc:creator>Sharcho</dc:creator>
	</item>
	</channel>
</rss>
