Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Tue, Dec 6, 2011 at 3:40 PM, Doran, Michael D wrote: > > > Current trends certainly go in the opposite direction, look at jQuery > > Mobile. > > I agree that jQuery Mobile is very popular now. However, that in no way > negates the caution. One could consider it as a "tragedy of the commons" > in which a user's iPhone battery is the shared resource. Why should I as a > developer (rationally consulting my own self-interest) conserve battery > power that doesn't belong to me, just so some other developer's app can use > that resource? I'm just playing the devil's advocate here. ;-) > > You're taking it as given that the use of JavaScript on a mobile device is significantly less energy-efficient than an approach that would exercise only the HTML parsing path. Be careful here, intuition can be misleading. Devices cannot send HTML to their displays. It takes energy to parse it, and energy to render it. Time is roughly proportional to energy. Where do you think most time/energy is spent in? (page-provided) JavaScript execution, HTML parsing, or page layout/rendering? Based on the information I have available to me (I'd appreciate pointers to other studies), JS execution does not dominate - it ranks last behind Page layout and rendering [1], even for sites that are JS heavy, such as webmail sites. Interestingly, a large part of that is evaluating CSS selectors. On a related note, let me point out that there are many ways to change the DOM on the client. Client-side templating frameworks such as knockout.js or jQuery tmpl produce HTML (which then must be parsed), but modern AJAX frameworks such as ZK don't produce any HTML at all, skipping parsing altogether. I meant to add another reason why at this point teaching newbies an AJAX style that relies on HTML-returning entry points is a really bad idea, and that is the move from read-only applications (like Nate's) to applications that actually update state on the server. In this case, multiple parts of the client page (perhaps a label here, a link there) need to be updated. Expressing this in HTML is cumbersome, to say the least. (As an aside, I note that AJAX frameworks such as ZK, which pursued the HTML approach in their first iterations, have moved away from it. Compare the client/server traffic on a ZK 3.x application to the one in a ZK 5. app to see this.) For those interested in how to use one of possible client-side approaches I'm suggesting, I prototyped Nate's application using only client-side templating: http://libx.lib.vt.edu/services/popsubjects/cs/ It uses knockout.js's data binding facilities as well as (due to qTip 1.0's design) the jQuery tmpl engine. Read the (small, self-contained) source to learn about the server-side entry points. (I should point out that in this case, the need for the book cover ISBNs to be retrieved remotely is somewhat contrived; they should probably be sent along with the page in the first place.) A side effect of this JSON-oriented design is that it results in 2 nice JSON-P web services that can be embedded/used in other pages/applications. - Godmar [1] http://www.eecs.berkeley.edu/~lmeyerov/projects/pbrowser/pubfiles/login.pdf
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
> It's certainly true that limited energy motivates the need to minimize > client processing, but the conclusion that this then means server > generation of static HTML is not clear. I'm not sure anyone was drawing that conclusion. It was offered up as factor to consider. > Current trends certainly go in the opposite direction, look at jQuery > Mobile. I agree that jQuery Mobile is very popular now. However, that in no way negates the caution. One could consider it as a "tragedy of the commons" in which a user's iPhone battery is the shared resource. Why should I as a developer (rationally consulting my own self-interest) conserve battery power that doesn't belong to me, just so some other developer's app can use that resource? I'm just playing the devil's advocate here. ;-) -- Michael [1] A dilemma arising from the situation in which multiple individuals, acting independently and rationally consulting their own self-interest, will ultimately deplete a shared limited resource, even when it is clear that it is not in anyone's long-term interest for this to happen. http://en.wikipedia.org/wiki/Tragedy_of_the_commons > -Original Message- > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > Godmar Back > Sent: Tuesday, December 06, 2011 12:43 PM > To: CODE4LIB@LISTSERV.ND.EDU > Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > > On Tue, Dec 6, 2011 at 11:22 AM, Doran, Michael D wrote: > > > > You had earlier asked the question whether to do things client or > server > > > side - well in this example, the correct answer is to do it client- > side. > > > (Yours is a read-only application, where none of the advantages of > > > server-side processing applies.) > > > > One thing to take into consideration when weighing the advantages of > > server-side vs. client-side processing, is whether the web app is likely > to > > be used on mobile devices. Douglas Crockford, speaking about the fact > that > > JavaScript has become the de fact universal runtime, cautions: "Which I > > think puts even more pressure on getting JavaScript to go fast. > > Particularly as we're now going into mobile. Moore's Law doesn't apply to > > batteries. So how much time we're wasting interpreting stuff really > matters > > there. The cycles count."[1] Personally, I don't know enough to know how > > significant the impact would be. However, I understand Douglas Crockford > > knows a little something about JavaScript and JSON. > > > > > It's certainly true that limited energy motivates the need to minimize > client processing, but the conclusion that this then means server > generation of static HTML is not clear. > > Current trends certainly go in the opposite direction, look at jQuery > Mobile. > > - Godmar
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
Solved the image matching regexp issue: if the search term was more than one word, it needed to be rewritten for the query using a + rather than a space between the words. as for hitting the catalog with searches over and over, I suppose there is a way to cache pages rather than pound the server over and over, right? I'll look into that. Godmar, would you mind passing along your PHP script so I can how exactly you created that JSON? On Tue, Dec 6, 2011 at 10:38 AM, Godmar Back wrote: > On Tue, Dec 6, 2011 at 11:18 AM, Nate Hill > wrote: > > > I attached the app as it stands now. There's something wrong w/ the > regex > > matching in catscrape.php so only some of the images are coming through. > > > > No, it's not the regexp. You're simply scraping syndetics links, without > checking if syndetics has or does not have an image for those ISBNs. Those > searches where the first four hits have jackets display, the others don't. > > > > Also: should I be sweating the fact that basically every time someone > > mouses over one of these boxes they are hitting our library catalog with > a > > query? It struck me that this might be unwise. But I don't know either > > way. > > > > > Yes, it's unwise, especially since the results won't change (much). > > - Godmar > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Tue, Dec 6, 2011 at 1:57 PM, Jonathan Rochkind wrote: > On 12/6/2011 1:42 PM, Godmar Back wrote: > >> Current trends certainly go in the opposite direction, look at jQuery >> Mobile. >> > > Hmm, JQuery mobile still operates on valid and functional HTML delivered > by the server. In fact, one of the designs of JQuery mobile is indeed to > degrade to a non-JS version in "feature phones" (you know, eg, flip phones > with a web browser but probably no javascript). The non-JS version it > degrades to is the same HTML that was delivered to the browser in either > way, just not enhanced by JQuery Mobile. > My argument was that current platforms, such as jQuery mobile, heavily rely on JavaScript on the very platforms on which Crockford statement points out it would be wise to save energy. Look at the jQuery Mobile documentation, A-grade platforms: http://jquerymobile.com/demos/1.0/docs/about/platforms.html If I were writing AJAX requests for an application targetted mainly at > JQuery Mobile... I'd be likely to still have the server delivery HTML to > the AJAX request, then have js insert it into the page and trigger JQuery > Mobile enhancements on it. > > I wouldn't. Return JSON and interpret or template the result. - Godmar
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On 12/6/2011 1:42 PM, Godmar Back wrote: Current trends certainly go in the opposite direction, look at jQuery Mobile. Hmm, JQuery mobile still operates on valid and functional HTML delivered by the server. In fact, one of the designs of JQuery mobile is indeed to degrade to a non-JS version in "feature phones" (you know, eg, flip phones with a web browser but probably no javascript). The non-JS version it degrades to is the same HTML that was delivered to the browser in either way, just not enhanced by JQuery Mobile. If I were writing AJAX requests for an application targetted mainly at JQuery Mobile... I'd be likely to still have the server delivery HTML to the AJAX request, then have js insert it into the page and trigger JQuery Mobile enhancements on it. - Godmar
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Tue, Dec 6, 2011 at 11:22 AM, Doran, Michael D wrote: > > You had earlier asked the question whether to do things client or server > > side - well in this example, the correct answer is to do it client-side. > > (Yours is a read-only application, where none of the advantages of > > server-side processing applies.) > > One thing to take into consideration when weighing the advantages of > server-side vs. client-side processing, is whether the web app is likely to > be used on mobile devices. Douglas Crockford, speaking about the fact that > JavaScript has become the de fact universal runtime, cautions: "Which I > think puts even more pressure on getting JavaScript to go fast. > Particularly as we're now going into mobile. Moore's Law doesn't apply to > batteries. So how much time we're wasting interpreting stuff really matters > there. The cycles count."[1] Personally, I don't know enough to know how > significant the impact would be. However, I understand Douglas Crockford > knows a little something about JavaScript and JSON. > > It's certainly true that limited energy motivates the need to minimize client processing, but the conclusion that this then means server generation of static HTML is not clear. Current trends certainly go in the opposite direction, look at jQuery Mobile. - Godmar
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
php has some nice and fast csv parsing abilities, use them as a source for your database. can then remove any regexp need still simple for the users snippet taken from one of my csv readers showing the prints in comments so you can see the data in an array this also keeps memory footprint down $row = 1; $fp = fopen ($fromdir.$file,"r"); while ($data = fgetcsv ($fp, 1000, ",")) {//readlines in csv $num = count ($data); //print " $num fields in line $row: "; $row++; //for ($c=0; $c<$num; $c++) { //print "'".$data[$c] . "' "; //} //print ""; } Dave Caroline On Tue, Dec 6, 2011 at 6:32 PM, Nate Hill wrote: > csv files are what I have- they are easy for the not-technically inclined > staff to create and then save to a folder. I was really just hoping to > make this easy on the people who make the reports. > > > On Tue, Dec 6, 2011 at 10:21 AM, Dave Caroline > wrote: > >> I dont understand the thinking and waste of time scanning entire csv >> files where a database table with good indexing can be a lot faster >> and use less server memory. >> >> Do the work once up front when the data becomes available not on every >> page draw. >> >> I subscribe to the read/send and mangle as little as possible(server >> and client) on a web page view >> >> Dave Caroline >> > > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Tue, Dec 6, 2011 at 11:18 AM, Nate Hill wrote: > I attached the app as it stands now. There's something wrong w/ the regex > matching in catscrape.php so only some of the images are coming through. > No, it's not the regexp. You're simply scraping syndetics links, without checking if syndetics has or does not have an image for those ISBNs. Those searches where the first four hits have jackets display, the others don't. > Also: should I be sweating the fact that basically every time someone > mouses over one of these boxes they are hitting our library catalog with a > query? It struck me that this might be unwise. But I don't know either > way. > > Yes, it's unwise, especially since the results won't change (much). - Godmar
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
csv files are what I have- they are easy for the not-technically inclined staff to create and then save to a folder. I was really just hoping to make this easy on the people who make the reports. On Tue, Dec 6, 2011 at 10:21 AM, Dave Caroline wrote: > I dont understand the thinking and waste of time scanning entire csv > files where a database table with good indexing can be a lot faster > and use less server memory. > > Do the work once up front when the data becomes available not on every > page draw. > > I subscribe to the read/send and mangle as little as possible(server > and client) on a web page view > > Dave Caroline > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I dont understand the thinking and waste of time scanning entire csv files where a database table with good indexing can be a lot faster and use less server memory. Do the work once up front when the data becomes available not on every page draw. I subscribe to the read/send and mangle as little as possible(server and client) on a web page view Dave Caroline
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
> I couldn't get json_encode() going on the server at work. This usually means your server is running an older version of PHP. If it's OS is RHEL 5, then you've likely got PHP 5.1.6 installed. http://php.net/manual/en/function.json-encode.php json_encode PHP 5 >= 5.2.0 --Dave - David Walker Library Web Services Manager California State University -Original Message- From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of Nate Hill Sent: Tuesday, December 06, 2011 8:18 AM To: CODE4LIB@LISTSERV.ND.EDU Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable I attached the app as it stands now. There's something wrong w/ the regex matching in catscrape.php so only some of the images are coming through. A bit more background info: Someone said 'it's not that much data'. Indeed it isn't, but that is because I intentionally gave myself an extremely simple data set to build/test with. I'd anticipate more complex data sets in the future. The .csv files are not generated automatically, we have a product called CollectionHQ that produces reports based on monthly data dumps from our ILS. I was planning to create a folder that the people who run these reports can simply save the csv files to, and then the web app would just work without them having to think about it. A bit of a side note, but I actually was taking the JSON approach briefly and it was working on my MAMP but for some reason I couldn't get json_encode() going on the server at work. I fiddled around w/ the .ini file a little while thinking I might need to do something there, got bored, and decided to take a different approach. Also: should I be sweating the fact that basically every time someone mouses over one of these boxes they are hitting our library catalog with a query? It struck me that this might be unwise. But I don't know either way. Thanks all. Do with this what you will, even if that is nothing. Just following the conversation has been enlightening. Nate On Tue, Dec 6, 2011 at 7:27 AM, Erik Hatcher wrote: > Again, with jrock... I was replying to the general "Ajax requests > returning HTML is outdated" theme, not to Nate's actual application. > > Certainly returning objects as code or data to a component (like, say, > SIMILE Timeline) is a reasonable use of data coming back from Ajax > requests, and covered in my "it depends" response :) > > A defender of the old? Only in as much as the old is simpler, > cleaner, and leaner than all the new wheels being invented. I'm > pragmatic, not dogmatic. > >Erik > > > On Dec 6, 2011, at 09:34 , Godmar Back wrote: > > > On Tue, Dec 6, 2011 at 8:38 AM, Erik Hatcher > wrote: > > > >> I'm with jrock on this one. But maybe I'm a luddite that didn't get > the > >> memo either (but I am credited for being one of the instrumental > >> folks > in > >> the Ajax world, heh - in one or more of the Ajax books out there, > >> us old timers called it "remote scripting"). > >> > >> > > On the in-jest rhetorical front, I'm wondering if referring to > > oneself as oldtimer helps in defending against insinuations that > > opposing technological change makes one a defender of the old ;-) > > > > But: > > > > > >> What I hate hate hate about seeing JSON being returned from a > >> server for the browser to generate the view is stuff like: > >> > >> string = "" + some_data_from_JSON + ""; > >> > >> That embodies everything that is wrong about Ajax + JSON. > >> > >> > > That's exactly why you use new libraries such as knockout.js, to > > avoid > just > > that. Client-side template engines with automatic data-bindings. > > > > Alternatively, AJAX frameworks use JSON and then interpret the > > returned objects as code. Take a look at the client/server traffic > > produced by ZK, for instance. > > > > > >> As Jonathan said, the server is already generating dynamic HTML... > >> why have it return > > > > > > It isn't. There is no already generating anything server, it's a new > > app Nate is writing. (Unless you count his work of the past two > > days). The dynamic HTML he's generating is heavily tailored to his > > JS. There's extremely tight coupling, which now exists across > > multiple files written > in > > multiple languages. Simply avoidable bad software engineering. > > That's not even making the computational cost argument that avoiding > > templa
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
> You had earlier asked the question whether to do things client or server > side - well in this example, the correct answer is to do it client-side. > (Yours is a read-only application, where none of the advantages of > server-side processing applies.) One thing to take into consideration when weighing the advantages of server-side vs. client-side processing, is whether the web app is likely to be used on mobile devices. Douglas Crockford, speaking about the fact that JavaScript has become the de fact universal runtime, cautions: "Which I think puts even more pressure on getting JavaScript to go fast. Particularly as we're now going into mobile. Moore's Law doesn't apply to batteries. So how much time we're wasting interpreting stuff really matters there. The cycles count."[1] Personally, I don't know enough to know how significant the impact would be. However, I understand Douglas Crockford knows a little something about JavaScript and JSON. -- Michael [1] Quoted in "Coders at Work" by Peter Seibel, pg. 100 # Michael Doran, Systems Librarian # University of Texas at Arlington # 817-272-5326 office # 817-688-1926 mobile # do...@uta.edu # http://rocky.uta.edu/doran/ > -Original Message- > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > Godmar Back > Sent: Monday, December 05, 2011 5:31 PM > To: CODE4LIB@LISTSERV.ND.EDU > Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > > FWIW, I would not send HTML back to the client in an AJAX request - that > style of AJAX fell out of favor years ago. > > Send back JSON instead and keep the view logic client-side. Consider using > a library such as knockout.js. Instead of your current (difficult to > maintain) mix of PhP and client-side JavaScript, you'll end up with a > static HTML page, a couple of clean JSON services (for checked-out per > subject, and one for the syndetics ids of the first 4 covers), and clean > HTML templates. > > You had earlier asked the question whether to do things client or server > side - well in this example, the correct answer is to do it client-side. > (Yours is a read-only application, where none of the advantages of > server-side processing applies.) > > - Godmar > > On Mon, Dec 5, 2011 at 6:18 PM, Nate Hill wrote: > > > Something quite like that, my friend! > > Cheers > > N > > > > On Mon, Dec 5, 2011 at 3:10 PM, Walker, David > > wrote: > > > > > I gotcha. More information is, indeed, better. ;-) > > > > > > So, on the PHP side, you just need to grab the term from the query > > > string, like this: > > > > > > $searchterm = $_GET['query']; > > > > > > And then in your JavaScript code, you'll send an AJAX request, like: > > > > > > http://www.natehill.net/vizstuff/catscrape.php?query=Cooking > > > > > > Is that what you're looking for? > > > > > > --Dave > > > > > > ----- > > > David Walker > > > Library Web Services Manager > > > California State University > > > > > > > > > -Original Message- > > > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > > > Nate Hill > > > Sent: Monday, December 05, 2011 3:00 PM > > > To: CODE4LIB@LISTSERV.ND.EDU > > > Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > > > > > > As always, I provided too little information. Dave, it's much more > > > involved than that > > > > > > I'm trying to make a kind of visual browser of popular materials from > one > > > of our branches from a .csv file. > > > > > > In order to display book covers for a series of searches by keyword, I > > > query the catalog, scrape out only the syndetics images, and then > > display 4 > > > of them. The problem is that I've hardcoded in a search for 'Drawing', > > > rather than dynamically pulling the correct term and putting it into > the > > > catalog query. > > > > > > Here's the work in process, and I believe it will only work in Chrome > > > right now. > > > http://www.natehill.net/vizstuff/donerightclasses.php > > > > > > I may have a solution, Jason's idea got me part way there. I looked > all > > > over the place for that little snippet he sent over! > > > > > > Thanks! > > > > > > > > > > > > On Mon, Dec 5, 2011 at 2:44 PM, Walker, David > > > wrote
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
Again, with jrock... I was replying to the general "Ajax requests returning HTML is outdated" theme, not to Nate's actual application. Certainly returning objects as code or data to a component (like, say, SIMILE Timeline) is a reasonable use of data coming back from Ajax requests, and covered in my "it depends" response :) A defender of the old? Only in as much as the old is simpler, cleaner, and leaner than all the new wheels being invented. I'm pragmatic, not dogmatic. Erik On Dec 6, 2011, at 09:34 , Godmar Back wrote: > On Tue, Dec 6, 2011 at 8:38 AM, Erik Hatcher wrote: > >> I'm with jrock on this one. But maybe I'm a luddite that didn't get the >> memo either (but I am credited for being one of the instrumental folks in >> the Ajax world, heh - in one or more of the Ajax books out there, us old >> timers called it "remote scripting"). >> >> > On the in-jest rhetorical front, I'm wondering if referring to oneself as > oldtimer helps in defending against insinuations that opposing > technological change makes one a defender of the old ;-) > > But: > > >> What I hate hate hate about seeing JSON being returned from a server for >> the browser to generate the view is stuff like: >> >> string = "" + some_data_from_JSON + ""; >> >> That embodies everything that is wrong about Ajax + JSON. >> >> > That's exactly why you use new libraries such as knockout.js, to avoid just > that. Client-side template engines with automatic data-bindings. > > Alternatively, AJAX frameworks use JSON and then interpret the returned > objects as code. Take a look at the client/server traffic produced by ZK, > for instance. > > >> As Jonathan said, the server is already generating dynamic HTML... why >> have it return > > > It isn't. There is no already generating anything server, it's a new app > Nate is writing. (Unless you count his work of the past two days). The > dynamic HTML he's generating is heavily tailored to his JS. There's > extremely tight coupling, which now exists across multiple files written in > multiple languages. Simply avoidable bad software engineering. That's not > even making the computational cost argument that avoiding template > processing on the server is cheaper. And with respect to Jonathan's > argument of degradation, a degraded version of his app (presumably) would > use - or something like that, it'd look nothing like what's he > showed us yesterday. > > Heh - the proof of the pudding is in the eating. Why don't we create 2 > versions of Nate's app, one with mixed server/client - like the one he's > completing now, and I create the client-side based one, and then we compare > side by side? I'll work with Nate on that. > > - Godmar > > [ I hope it's ok to snip off the rest of the email trail in my reply. ]
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I'll admit I haven't spent a lot of time investigating/analyzing this particular application -- it's quite possible an all-JS app is the right choice here. I was just responding to the suggestion that returning HTML to AJAX was "out of style" and shouldn't be done anymore; with the implication I picked up that (nearly) ALL apps should be almost all JS, use JS templating engines, etc., that this is the "right" "new" way to write web apps. I think this sends the wrong message to newbies. It's true that it is very trendy these days to write all JS apps, which if they function at all without JS do so with a completely seperate codepath (this is NOT "progressive enhancement", although it is a way of ensuring non-JS accessibility). Yeah, it's trendy, but I think it's frequently (but not always, true) the wrong choice when it's done. If you do provide a completely separate codepath for non-JS, this can be harder to maintain than actual progressive enhancement. And pure JS either way can easily make your app a poor web citizen of the web, harder to screen-scrape or spider, harder to find URLs to link to certain parts of the app, etc. (eg, http://www.tbray.org/ongoing/When/201x/2011/02/09/Hash-Blecch ) But, sure, maybe in this particular case pure-JS is a good way to go, I haven't spent enough time looking at or thinking about it to have an opinion. Sure, if you've already started down the path of using a JS templating/view-rendering engine, and that's something you/want need to do anyway, you might as well stick to it, I guess. I just reacted to the suggestion that doing anything _but_ this is "out of style", or an old bad way of doing things. If writing apps that produce HTML with progressive enhancement is out of style, then I don't want to be fashionable! From: Code for Libraries [CODE4LIB@LISTSERV.ND.EDU] on behalf of Godmar Back [god...@gmail.com] Sent: Tuesday, December 06, 2011 9:34 AM To: CODE4LIB@LISTSERV.ND.EDU Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable On Tue, Dec 6, 2011 at 8:38 AM, Erik Hatcher wrote: > I'm with jrock on this one. But maybe I'm a luddite that didn't get the > memo either (but I am credited for being one of the instrumental folks in > the Ajax world, heh - in one or more of the Ajax books out there, us old > timers called it "remote scripting"). > > On the in-jest rhetorical front, I'm wondering if referring to oneself as oldtimer helps in defending against insinuations that opposing technological change makes one a defender of the old ;-) But: > What I hate hate hate about seeing JSON being returned from a server for > the browser to generate the view is stuff like: > > string = "" + some_data_from_JSON + ""; > > That embodies everything that is wrong about Ajax + JSON. > > That's exactly why you use new libraries such as knockout.js, to avoid just that. Client-side template engines with automatic data-bindings. Alternatively, AJAX frameworks use JSON and then interpret the returned objects as code. Take a look at the client/server traffic produced by ZK, for instance. > As Jonathan said, the server is already generating dynamic HTML... why > have it return It isn't. There is no already generating anything server, it's a new app Nate is writing. (Unless you count his work of the past two days). The dynamic HTML he's generating is heavily tailored to his JS. There's extremely tight coupling, which now exists across multiple files written in multiple languages. Simply avoidable bad software engineering. That's not even making the computational cost argument that avoiding template processing on the server is cheaper. And with respect to Jonathan's argument of degradation, a degraded version of his app (presumably) would use - or something like that, it'd look nothing like what's he showed us yesterday. Heh - the proof of the pudding is in the eating. Why don't we create 2 versions of Nate's app, one with mixed server/client - like the one he's completing now, and I create the client-side based one, and then we compare side by side? I'll work with Nate on that. - Godmar [ I hope it's ok to snip off the rest of the email trail in my reply. ]
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
> Is it too late to dedicate a presentation slot to a performance? > (Whoa, actually, seriously, a Code4Lib talent show would be AWESOME.) The rails conf in baltimore a couple years ago had an evening jam session slot. Sadly, it's really a pain bringing the accordion on an airplane.
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Tue, Dec 6, 2011 at 8:38 AM, Erik Hatcher wrote: > I'm with jrock on this one. But maybe I'm a luddite that didn't get the > memo either (but I am credited for being one of the instrumental folks in > the Ajax world, heh - in one or more of the Ajax books out there, us old > timers called it "remote scripting"). > > On the in-jest rhetorical front, I'm wondering if referring to oneself as oldtimer helps in defending against insinuations that opposing technological change makes one a defender of the old ;-) But: > What I hate hate hate about seeing JSON being returned from a server for > the browser to generate the view is stuff like: > > string = "" + some_data_from_JSON + ""; > > That embodies everything that is wrong about Ajax + JSON. > > That's exactly why you use new libraries such as knockout.js, to avoid just that. Client-side template engines with automatic data-bindings. Alternatively, AJAX frameworks use JSON and then interpret the returned objects as code. Take a look at the client/server traffic produced by ZK, for instance. > As Jonathan said, the server is already generating dynamic HTML... why > have it return It isn't. There is no already generating anything server, it's a new app Nate is writing. (Unless you count his work of the past two days). The dynamic HTML he's generating is heavily tailored to his JS. There's extremely tight coupling, which now exists across multiple files written in multiple languages. Simply avoidable bad software engineering. That's not even making the computational cost argument that avoiding template processing on the server is cheaper. And with respect to Jonathan's argument of degradation, a degraded version of his app (presumably) would use - or something like that, it'd look nothing like what's he showed us yesterday. Heh - the proof of the pudding is in the eating. Why don't we create 2 versions of Nate's app, one with mixed server/client - like the one he's completing now, and I create the client-side based one, and then we compare side by side? I'll work with Nate on that. - Godmar [ I hope it's ok to snip off the rest of the email trail in my reply. ]
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Mon, Dec 5, 2011 at 5:00 PM, Nate Hill wrote: > Here's the work in process, and I believe it will only work in Chrome right > now. > http://www.natehill.net/vizstuff/donerightclasses.php In this case, it looks like there really isn't that much data. I'd preprocess everything into a big JSON object and just have all the data instead of using AJAX for this task. And actually, if you have some automated process writing the .CSV file, I might have that same process (or a follow-on process) generate your JSON and serve it statically instead of doing it on the fly in PHP. -n
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Mon, Dec 5, 2011 at 8:04 PM, Godmar Back wrote: > That said, I'm genuinely interested in what others are thinking/have > experienced. I've heard the "don't send HTML" argument, but in my experience, writing HTML template code and then Javascript code to generate the same HTML is bad. They either have slight inconsistencies, or I change one and forget about the other, or something else. My rule of thumb: If a UI element relies on JS for its functionality, rendering it with JS is fine. If it's supposed to show up and operate without JS, render it with your templating engine. Render each thing in only one place. Whether an app should require javascript or use progressive enhancement depends on the app -- but "this just needs javascript" is not a decision to make lightly; it's hard to change your mind two months in. -n
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
st need to grab the term from the query > >>>> string, like this: > >>>> > >>>> $searchterm = $_GET['query']; > >>>> > >>>> And then in your JavaScript code, you'll send an AJAX request, like: > >>>> > >>>> http://www.natehill.net/vizstuff/catscrape.php?query=Cooking > >>>> > >>>> Is that what you're looking for? > >>>> > >>>> --Dave > >>>> > >>>> - > >>>> David Walker > >>>> Library Web Services Manager > >>>> California State University > >>>> > >>>> > >>>> -Original Message- > >>>> From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf > Of > >>>> Nate Hill > >>>> Sent: Monday, December 05, 2011 3:00 PM > >>>> To: CODE4LIB@LISTSERV.ND.EDU > >>>> Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > >>>> > >>>> As always, I provided too little information. Dave, it's much more > >>>> involved than that > >>>> > >>>> I'm trying to make a kind of visual browser of popular materials from > one > >>>> of our branches from a .csv file. > >>>> > >>>> In order to display book covers for a series of searches by keyword, I > >>>> query the catalog, scrape out only the syndetics images, and then > >>> display 4 > >>>> of them. The problem is that I've hardcoded in a search for > 'Drawing', > >>>> rather than dynamically pulling the correct term and putting it into > the > >>>> catalog query. > >>>> > >>>> Here's the work in process, and I believe it will only work in Chrome > >>>> right now. > >>>> http://www.natehill.net/vizstuff/donerightclasses.php > >>>> > >>>> I may have a solution, Jason's idea got me part way there. I looked > all > >>>> over the place for that little snippet he sent over! > >>>> > >>>> Thanks! > >>>> > >>>> > >>>> > >>>> On Mon, Dec 5, 2011 at 2:44 PM, Walker, David > >>>> wrote: > >>>> > >>>>>> And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > >>>>>> effect on the client side then I need to make an Ajax request, > >>> correct? > >>>>> What you probably want to do here, Nate, is simply output the PHP > >>>>> variable in your HTML response, like this: > >>>>> > >>>>> > >>>>> > >>>>> And then in your JavaScript code, you can manipulate the text through > >>>>> the DOM like this: > >>>>> > >>>>> $('#foo').html('Cooking'); > >>>>> > >>>>> --Dave > >>>>> > >>>>> - > >>>>> David Walker > >>>>> Library Web Services Manager > >>>>> California State University > >>>>> > >>>>> > >>>>> -Original Message- > >>>>> From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf > >>>>> Of Nate Hill > >>>>> Sent: Monday, December 05, 2011 2:09 PM > >>>>> To: CODE4LIB@LISTSERV.ND.EDU > >>>>> Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable > >>>>> > >>>>> If I have in my PHP script a variable... > >>>>> > >>>>> $searchterm = 'Drawing'; > >>>>> > >>>>> And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > >>>>> effect on the client side then I need to make an Ajax request, > correct? > >>>>> What I can't figure out is what that is supposed to look like... > >>>>> something like... > >>>>> > >>>>> $.ajax({ > >>>>> type: "POST", > >>>>> url: "myfile.php", > >>>>> data: "...not sure how to write what goes here to make it > >>> 'Cooking'..." > >>>>> }); > >>>>> > >>>>> Any ideas? > >>>>> > >>>>> > >>>>> -- > >>>>> Nate Hill > >>>>> nathanielh...@gmail.com > >>>>> http://www.natehill.net > >>>>> > >>>> > >>>> > >>>> -- > >>>> Nate Hill > >>>> nathanielh...@gmail.com > >>>> http://www.natehill.net > >>>> > >>> > >>> > >>> -- > >>> Nate Hill > >>> nathanielh...@gmail.com > >>> http://www.natehill.net > >>> >
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I'm with jrock on this one. But maybe I'm a luddite that didn't get the memo either (but I am credited for being one of the instrumental folks in the Ajax world, heh - in one or more of the Ajax books out there, us old timers called it "remote scripting"). What I hate hate hate about seeing JSON being returned from a server for the browser to generate the view is stuff like: string = "" + some_data_from_JSON + ""; That embodies everything that is wrong about Ajax + JSON. As Jonathan said, the server is already generating dynamic HTML... why have it return JSON and move processing/templating to the client for some things but not other things? Rhetorical question... of course "it depends" on the application. If everything is entirely client-side generated, then sure. But for "traditional" webapps, JSON to the client to simply piece it together as HTML is hideous. I spoke to this a bit at my recent ApacheCon talk, slides are here: <http://www.slideshare.net/erikhatcher/solr-flair-10173707> slides 4 and 8 particularly on this topic. So in short, opinions differ on the "right" way to do Ajax obviously. It depends, no question, on the bigger picture and architectural pieces in play, but there is absolutely nothing wrong with having HTML being returned from the server for partial pieces of the page. An in many cases it's the cleanest way to do it anyway. Erik On Dec 5, 2011, at 18:45 , Jonathan Rochkind wrote: > I still like sending HTML back from my server. I guess I never got the > message that that was out of style, heh. > > My server application already has logic for creating HTML from templates, and > quite possibly already creates this exact same piece of HTML in some other > place, possibly for use with non-AJAX fallbacks, or some other context where > that snippet of HTML needs to be rendered. I prefer to re-use this logic > that's already on the server, rather than have a duplicate HTML > generating/templating system in the javascript too. It's working fine for > me, in my use patterns. > > Now, certainly, if you could eliminate any PHP generation of HTML at all, as > I think Godmar is suggesting, and basically have a pure Javascript app -- > that would be another approach that avoids duplication of HTML generating > logic in both JS and PHP. That sounds fine too. But I'm still writing apps > that degrade if you have no JS (including for web spiders that have no JS, > for instance), and have nice REST-ish URLs, etc. If that's not a > requirement and you can go all JS, then sure. But I wouldn't say that making > apps that use progressive enhancement with regard to JS and degrade fine if > you don't have is "out of style", or if it is, it ought not to be! > > Jonathan > > On 12/5/2011 6:31 PM, Godmar Back wrote: >> FWIW, I would not send HTML back to the client in an AJAX request - that >> style of AJAX fell out of favor years ago. >> >> Send back JSON instead and keep the view logic client-side. Consider using >> a library such as knockout.js. Instead of your current (difficult to >> maintain) mix of PhP and client-side JavaScript, you'll end up with a >> static HTML page, a couple of clean JSON services (for checked-out per >> subject, and one for the syndetics ids of the first 4 covers), and clean >> HTML templates. >> >> You had earlier asked the question whether to do things client or server >> side - well in this example, the correct answer is to do it client-side. >> (Yours is a read-only application, where none of the advantages of >> server-side processing applies.) >> >> - Godmar >> >> On Mon, Dec 5, 2011 at 6:18 PM, Nate Hill wrote: >> >>> Something quite like that, my friend! >>> Cheers >>> N >>> >>> On Mon, Dec 5, 2011 at 3:10 PM, Walker, David >>> wrote: >>> >>>> I gotcha. More information is, indeed, better. ;-) >>>> >>>> So, on the PHP side, you just need to grab the term from the query >>>> string, like this: >>>> >>>> $searchterm = $_GET['query']; >>>> >>>> And then in your JavaScript code, you'll send an AJAX request, like: >>>> >>>> http://www.natehill.net/vizstuff/catscrape.php?query=Cooking >>>> >>>> Is that what you're looking for? >>>> >>>> --Dave >>>> >>>> - >>>> David Walker >>>> Library Web Services Manager >>>> California State University >>>>
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I'd be really curious to see the different ways you all speak of accomplishing this, and would stand to learn a lot along the way. As a beginner with much of this, I have patched together this app using methods and means that I know, rather than the 'right' way. So, that said, I'm sure I'm doing a lot of somewhat basic operations in a rather roundabout manner. Do correct me. I intentionally left this project at work today so I wouldn't play with it at home tonight, but in the morning I'll share the various files so anyone who feels like it can pick them apart and demonstrate their alternative (and likely far more efficient) ways of doing things. Thanks to all of you who have chimed in. Much appreciated. N On Mon, Dec 5, 2011 at 6:04 PM, Godmar Back wrote: > On Mon, Dec 5, 2011 at 6:45 PM, Jonathan Rochkind > wrote: > > > I still like sending HTML back from my server. I guess I never got the > > message that that was out of style, heh. > > > > > I suppose there are always some stalwart defenders of the status quo ;-) > > More seriously, I think I'd like to defend my statement. > > The purpose of graceful degradation is well-acknowledged - I don't think > no-JS browsers are much of a concern, but web spiders are and so are > probably ADA accessibility requirements, as well as low-bandwidth > environments. > > I do not believe, however, that such situation warrant any sharing of HTML > templates. If they do, it means your app is, well, perhaps outdated in that > it doesn't make full use of today's JS features. Certainly Gmail's "basic > html version for low bandwidth environments" shares no HTML templates with > the JS main app. In Nate's case, which is a heavily JS-dependent app (he > uses various jQuery plug-ins to drive his layout, as well as qtip for > tooltips), I find it difficult to see how any degraded environment would > share any HTML with his app. > > That said, I'm genuinely interested in what others are thinking/have > experienced. > > Also, for expository purposes, I'd love to prototype the client-side for > Nate's app. Then we could compare the mixed PhP server/client-side AJAX > version with the pure JS app I'm suggesting. > > - Godmar > > > On Mon, Dec 5, 2011 at 6:45 PM, Jonathan Rochkind > wrote: > > > I still like sending HTML back from my server. I guess I never got the > > message that that was out of style, heh. > > > > My server application already has logic for creating HTML from templates, > > and quite possibly already creates this exact same piece of HTML in some > > other place, possibly for use with non-AJAX fallbacks, or some other > > context where that snippet of HTML needs to be rendered. I prefer to > re-use > > this logic that's already on the server, rather than have a duplicate > HTML > > generating/templating system in the javascript too. It's working fine > for > > me, in my use patterns. > > > > Now, certainly, if you could eliminate any PHP generation of HTML at all, > > as I think Godmar is suggesting, and basically have a pure Javascript app > > -- that would be another approach that avoids duplication of HTML > > generating logic in both JS and PHP. That sounds fine too. But I'm still > > writing apps that degrade if you have no JS (including for web spiders > that > > have no JS, for instance), and have nice REST-ish URLs, etc. If that's > > not a requirement and you can go all JS, then sure. But I wouldn't say > > that making apps that use progressive enhancement with regard to JS and > > degrade fine if you don't have is "out of style", or if it is, it ought > not > > to be! > > > > Jonathan > > > > > > > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
On Mon, Dec 5, 2011 at 6:45 PM, Jonathan Rochkind wrote: > I still like sending HTML back from my server. I guess I never got the > message that that was out of style, heh. > > I suppose there are always some stalwart defenders of the status quo ;-) More seriously, I think I'd like to defend my statement. The purpose of graceful degradation is well-acknowledged - I don't think no-JS browsers are much of a concern, but web spiders are and so are probably ADA accessibility requirements, as well as low-bandwidth environments. I do not believe, however, that such situation warrant any sharing of HTML templates. If they do, it means your app is, well, perhaps outdated in that it doesn't make full use of today's JS features. Certainly Gmail's "basic html version for low bandwidth environments" shares no HTML templates with the JS main app. In Nate's case, which is a heavily JS-dependent app (he uses various jQuery plug-ins to drive his layout, as well as qtip for tooltips), I find it difficult to see how any degraded environment would share any HTML with his app. That said, I'm genuinely interested in what others are thinking/have experienced. Also, for expository purposes, I'd love to prototype the client-side for Nate's app. Then we could compare the mixed PhP server/client-side AJAX version with the pure JS app I'm suggesting. - Godmar On Mon, Dec 5, 2011 at 6:45 PM, Jonathan Rochkind wrote: > I still like sending HTML back from my server. I guess I never got the > message that that was out of style, heh. > > My server application already has logic for creating HTML from templates, > and quite possibly already creates this exact same piece of HTML in some > other place, possibly for use with non-AJAX fallbacks, or some other > context where that snippet of HTML needs to be rendered. I prefer to re-use > this logic that's already on the server, rather than have a duplicate HTML > generating/templating system in the javascript too. It's working fine for > me, in my use patterns. > > Now, certainly, if you could eliminate any PHP generation of HTML at all, > as I think Godmar is suggesting, and basically have a pure Javascript app > -- that would be another approach that avoids duplication of HTML > generating logic in both JS and PHP. That sounds fine too. But I'm still > writing apps that degrade if you have no JS (including for web spiders that > have no JS, for instance), and have nice REST-ish URLs, etc. If that's > not a requirement and you can go all JS, then sure. But I wouldn't say > that making apps that use progressive enhancement with regard to JS and > degrade fine if you don't have is "out of style", or if it is, it ought not > to be! > > Jonathan > > >
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
AHAH! On Mon, Dec 5, 2011 at 3:45 PM, Jonathan Rochkind wrote: > I still like sending HTML back from my server. I guess I never got the > message that that was out of style, heh. > > My server application already has logic for creating HTML from templates, > and quite possibly already creates this exact same piece of HTML in some > other place, possibly for use with non-AJAX fallbacks, or some other context > where that snippet of HTML needs to be rendered. I prefer to re-use this > logic that's already on the server, rather than have a duplicate HTML > generating/templating system in the javascript too. It's working fine for > me, in my use patterns. > > Now, certainly, if you could eliminate any PHP generation of HTML at all, as > I think Godmar is suggesting, and basically have a pure Javascript app -- > that would be another approach that avoids duplication of HTML generating > logic in both JS and PHP. That sounds fine too. But I'm still writing apps > that degrade if you have no JS (including for web spiders that have no JS, > for instance), and have nice REST-ish URLs, etc. If that's not a > requirement and you can go all JS, then sure. But I wouldn't say that > making apps that use progressive enhancement with regard to JS and degrade > fine if you don't have is "out of style", or if it is, it ought not to be! > > Jonathan > > > On 12/5/2011 6:31 PM, Godmar Back wrote: >> >> FWIW, I would not send HTML back to the client in an AJAX request - that >> style of AJAX fell out of favor years ago. >> >> Send back JSON instead and keep the view logic client-side. Consider using >> a library such as knockout.js. Instead of your current (difficult to >> maintain) mix of PhP and client-side JavaScript, you'll end up with a >> static HTML page, a couple of clean JSON services (for checked-out per >> subject, and one for the syndetics ids of the first 4 covers), and clean >> HTML templates. >> >> You had earlier asked the question whether to do things client or server >> side - well in this example, the correct answer is to do it client-side. >> (Yours is a read-only application, where none of the advantages of >> server-side processing applies.) >> >> - Godmar >> >> On Mon, Dec 5, 2011 at 6:18 PM, Nate Hill wrote: >> >>> Something quite like that, my friend! >>> Cheers >>> N >>> >>> On Mon, Dec 5, 2011 at 3:10 PM, Walker, David >>> wrote: >>> >>>> I gotcha. More information is, indeed, better. ;-) >>>> >>>> So, on the PHP side, you just need to grab the term from the query >>>> string, like this: >>>> >>>> $searchterm = $_GET['query']; >>>> >>>> And then in your JavaScript code, you'll send an AJAX request, like: >>>> >>>> http://www.natehill.net/vizstuff/catscrape.php?query=Cooking >>>> >>>> Is that what you're looking for? >>>> >>>> --Dave >>>> >>>> - >>>> David Walker >>>> Library Web Services Manager >>>> California State University >>>> >>>> >>>> -Original Message- >>>> From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of >>>> Nate Hill >>>> Sent: Monday, December 05, 2011 3:00 PM >>>> To: CODE4LIB@LISTSERV.ND.EDU >>>> Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable >>>> >>>> As always, I provided too little information. Dave, it's much more >>>> involved than that >>>> >>>> I'm trying to make a kind of visual browser of popular materials from >>>> one >>>> of our branches from a .csv file. >>>> >>>> In order to display book covers for a series of searches by keyword, I >>>> query the catalog, scrape out only the syndetics images, and then >>> >>> display 4 >>>> >>>> of them. The problem is that I've hardcoded in a search for 'Drawing', >>>> rather than dynamically pulling the correct term and putting it into the >>>> catalog query. >>>> >>>> Here's the work in process, and I believe it will only work in Chrome >>>> right now. >>>> http://www.natehill.net/vizstuff/donerightclasses.php >>>> >>>> I may have a solution, Jason's idea got me part way there. I looked all >>>> over t
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I still like sending HTML back from my server. I guess I never got the message that that was out of style, heh. My server application already has logic for creating HTML from templates, and quite possibly already creates this exact same piece of HTML in some other place, possibly for use with non-AJAX fallbacks, or some other context where that snippet of HTML needs to be rendered. I prefer to re-use this logic that's already on the server, rather than have a duplicate HTML generating/templating system in the javascript too. It's working fine for me, in my use patterns. Now, certainly, if you could eliminate any PHP generation of HTML at all, as I think Godmar is suggesting, and basically have a pure Javascript app -- that would be another approach that avoids duplication of HTML generating logic in both JS and PHP. That sounds fine too. But I'm still writing apps that degrade if you have no JS (including for web spiders that have no JS, for instance), and have nice REST-ish URLs, etc. If that's not a requirement and you can go all JS, then sure. But I wouldn't say that making apps that use progressive enhancement with regard to JS and degrade fine if you don't have is "out of style", or if it is, it ought not to be! Jonathan On 12/5/2011 6:31 PM, Godmar Back wrote: FWIW, I would not send HTML back to the client in an AJAX request - that style of AJAX fell out of favor years ago. Send back JSON instead and keep the view logic client-side. Consider using a library such as knockout.js. Instead of your current (difficult to maintain) mix of PhP and client-side JavaScript, you'll end up with a static HTML page, a couple of clean JSON services (for checked-out per subject, and one for the syndetics ids of the first 4 covers), and clean HTML templates. You had earlier asked the question whether to do things client or server side - well in this example, the correct answer is to do it client-side. (Yours is a read-only application, where none of the advantages of server-side processing applies.) - Godmar On Mon, Dec 5, 2011 at 6:18 PM, Nate Hill wrote: Something quite like that, my friend! Cheers N On Mon, Dec 5, 2011 at 3:10 PM, Walker, David wrote: I gotcha. More information is, indeed, better. ;-) So, on the PHP side, you just need to grab the term from the query string, like this: $searchterm = $_GET['query']; And then in your JavaScript code, you'll send an AJAX request, like: http://www.natehill.net/vizstuff/catscrape.php?query=Cooking Is that what you're looking for? --Dave - David Walker Library Web Services Manager California State University -Original Message- From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of Nate Hill Sent: Monday, December 05, 2011 3:00 PM To: CODE4LIB@LISTSERV.ND.EDU Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable As always, I provided too little information. Dave, it's much more involved than that I'm trying to make a kind of visual browser of popular materials from one of our branches from a .csv file. In order to display book covers for a series of searches by keyword, I query the catalog, scrape out only the syndetics images, and then display 4 of them. The problem is that I've hardcoded in a search for 'Drawing', rather than dynamically pulling the correct term and putting it into the catalog query. Here's the work in process, and I believe it will only work in Chrome right now. http://www.natehill.net/vizstuff/donerightclasses.php I may have a solution, Jason's idea got me part way there. I looked all over the place for that little snippet he sent over! Thanks! On Mon, Dec 5, 2011 at 2:44 PM, Walker, David wrote: And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on the client side then I need to make an Ajax request, correct? What you probably want to do here, Nate, is simply output the PHP variable in your HTML response, like this: And then in your JavaScript code, you can manipulate the text through the DOM like this: $('#foo').html('Cooking'); --Dave - David Walker Library Web Services Manager California State University -Original Message- From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of Nate Hill Sent: Monday, December 05, 2011 2:09 PM To: CODE4LIB@LISTSERV.ND.EDU Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable If I have in my PHP script a variable... $searchterm = 'Drawing'; And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on the client side then I need to make an Ajax request, correct? What I can't figure out is what that is supposed to look like... something like... $.ajax({ type: "POST", url: "myfile.php",
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
FWIW, I would not send HTML back to the client in an AJAX request - that style of AJAX fell out of favor years ago. Send back JSON instead and keep the view logic client-side. Consider using a library such as knockout.js. Instead of your current (difficult to maintain) mix of PhP and client-side JavaScript, you'll end up with a static HTML page, a couple of clean JSON services (for checked-out per subject, and one for the syndetics ids of the first 4 covers), and clean HTML templates. You had earlier asked the question whether to do things client or server side - well in this example, the correct answer is to do it client-side. (Yours is a read-only application, where none of the advantages of server-side processing applies.) - Godmar On Mon, Dec 5, 2011 at 6:18 PM, Nate Hill wrote: > Something quite like that, my friend! > Cheers > N > > On Mon, Dec 5, 2011 at 3:10 PM, Walker, David > wrote: > > > I gotcha. More information is, indeed, better. ;-) > > > > So, on the PHP side, you just need to grab the term from the query > > string, like this: > > > > $searchterm = $_GET['query']; > > > > And then in your JavaScript code, you'll send an AJAX request, like: > > > > http://www.natehill.net/vizstuff/catscrape.php?query=Cooking > > > > Is that what you're looking for? > > > > --Dave > > > > - > > David Walker > > Library Web Services Manager > > California State University > > > > > > -Original Message- > > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > > Nate Hill > > Sent: Monday, December 05, 2011 3:00 PM > > To: CODE4LIB@LISTSERV.ND.EDU > > Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > > > > As always, I provided too little information. Dave, it's much more > > involved than that > > > > I'm trying to make a kind of visual browser of popular materials from one > > of our branches from a .csv file. > > > > In order to display book covers for a series of searches by keyword, I > > query the catalog, scrape out only the syndetics images, and then > display 4 > > of them. The problem is that I've hardcoded in a search for 'Drawing', > > rather than dynamically pulling the correct term and putting it into the > > catalog query. > > > > Here's the work in process, and I believe it will only work in Chrome > > right now. > > http://www.natehill.net/vizstuff/donerightclasses.php > > > > I may have a solution, Jason's idea got me part way there. I looked all > > over the place for that little snippet he sent over! > > > > Thanks! > > > > > > > > On Mon, Dec 5, 2011 at 2:44 PM, Walker, David > > wrote: > > > > > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > > > > effect on the client side then I need to make an Ajax request, > correct? > > > > > > What you probably want to do here, Nate, is simply output the PHP > > > variable in your HTML response, like this: > > > > > > > > > > > > And then in your JavaScript code, you can manipulate the text through > > > the DOM like this: > > > > > > $('#foo').html('Cooking'); > > > > > > --Dave > > > > > > - > > > David Walker > > > Library Web Services Manager > > > California State University > > > > > > > > > -Original Message- > > > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf > > > Of Nate Hill > > > Sent: Monday, December 05, 2011 2:09 PM > > > To: CODE4LIB@LISTSERV.ND.EDU > > > Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable > > > > > > If I have in my PHP script a variable... > > > > > > $searchterm = 'Drawing'; > > > > > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > > > effect on the client side then I need to make an Ajax request, correct? > > > What I can't figure out is what that is supposed to look like... > > > something like... > > > > > > $.ajax({ > > > type: "POST", > > > url: "myfile.php", > > > data: "...not sure how to write what goes here to make it > 'Cooking'..." > > > }); > > > > > > Any ideas? > > > > > > > > > -- > > > Nate Hill > > > nathanielh...@gmail.com > > > http://www.natehill.net > > > > > > > > > > > -- > > Nate Hill > > nathanielh...@gmail.com > > http://www.natehill.net > > > > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
Something quite like that, my friend! Cheers N On Mon, Dec 5, 2011 at 3:10 PM, Walker, David wrote: > I gotcha. More information is, indeed, better. ;-) > > So, on the PHP side, you just need to grab the term from the query > string, like this: > > $searchterm = $_GET['query']; > > And then in your JavaScript code, you'll send an AJAX request, like: > > http://www.natehill.net/vizstuff/catscrape.php?query=Cooking > > Is that what you're looking for? > > --Dave > > - > David Walker > Library Web Services Manager > California State University > > > -Original Message- > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > Nate Hill > Sent: Monday, December 05, 2011 3:00 PM > To: CODE4LIB@LISTSERV.ND.EDU > Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable > > As always, I provided too little information. Dave, it's much more > involved than that > > I'm trying to make a kind of visual browser of popular materials from one > of our branches from a .csv file. > > In order to display book covers for a series of searches by keyword, I > query the catalog, scrape out only the syndetics images, and then display 4 > of them. The problem is that I've hardcoded in a search for 'Drawing', > rather than dynamically pulling the correct term and putting it into the > catalog query. > > Here's the work in process, and I believe it will only work in Chrome > right now. > http://www.natehill.net/vizstuff/donerightclasses.php > > I may have a solution, Jason's idea got me part way there. I looked all > over the place for that little snippet he sent over! > > Thanks! > > > > On Mon, Dec 5, 2011 at 2:44 PM, Walker, David > wrote: > > > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > > > effect on the client side then I need to make an Ajax request, correct? > > > > What you probably want to do here, Nate, is simply output the PHP > > variable in your HTML response, like this: > > > > > > > > And then in your JavaScript code, you can manipulate the text through > > the DOM like this: > > > > $('#foo').html('Cooking'); > > > > --Dave > > > > --------- > > David Walker > > Library Web Services Manager > > California State University > > > > > > -Original Message- > > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf > > Of Nate Hill > > Sent: Monday, December 05, 2011 2:09 PM > > To: CODE4LIB@LISTSERV.ND.EDU > > Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable > > > > If I have in my PHP script a variable... > > > > $searchterm = 'Drawing'; > > > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > > effect on the client side then I need to make an Ajax request, correct? > > What I can't figure out is what that is supposed to look like... > > something like... > > > > $.ajax({ > > type: "POST", > > url: "myfile.php", > > data: "...not sure how to write what goes here to make it 'Cooking'..." > > }); > > > > Any ideas? > > > > > > -- > > Nate Hill > > nathanielh...@gmail.com > > http://www.natehill.net > > > > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I gotcha. More information is, indeed, better. ;-) So, on the PHP side, you just need to grab the term from the query string, like this: $searchterm = $_GET['query']; And then in your JavaScript code, you'll send an AJAX request, like: http://www.natehill.net/vizstuff/catscrape.php?query=Cooking Is that what you're looking for? --Dave - David Walker Library Web Services Manager California State University -Original Message- From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of Nate Hill Sent: Monday, December 05, 2011 3:00 PM To: CODE4LIB@LISTSERV.ND.EDU Subject: Re: [CODE4LIB] jQuery Ajax request to update a PHP variable As always, I provided too little information. Dave, it's much more involved than that I'm trying to make a kind of visual browser of popular materials from one of our branches from a .csv file. In order to display book covers for a series of searches by keyword, I query the catalog, scrape out only the syndetics images, and then display 4 of them. The problem is that I've hardcoded in a search for 'Drawing', rather than dynamically pulling the correct term and putting it into the catalog query. Here's the work in process, and I believe it will only work in Chrome right now. http://www.natehill.net/vizstuff/donerightclasses.php I may have a solution, Jason's idea got me part way there. I looked all over the place for that little snippet he sent over! Thanks! On Mon, Dec 5, 2011 at 2:44 PM, Walker, David wrote: > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > > effect on the client side then I need to make an Ajax request, correct? > > What you probably want to do here, Nate, is simply output the PHP > variable in your HTML response, like this: > > > > And then in your JavaScript code, you can manipulate the text through > the DOM like this: > > $('#foo').html('Cooking'); > > --Dave > > - > David Walker > Library Web Services Manager > California State University > > > -Original Message- > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf > Of Nate Hill > Sent: Monday, December 05, 2011 2:09 PM > To: CODE4LIB@LISTSERV.ND.EDU > Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable > > If I have in my PHP script a variable... > > $searchterm = 'Drawing'; > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover > effect on the client side then I need to make an Ajax request, correct? > What I can't figure out is what that is supposed to look like... > something like... > > $.ajax({ > type: "POST", > url: "myfile.php", > data: "...not sure how to write what goes here to make it 'Cooking'..." > }); > > Any ideas? > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
As always, I provided too little information. Dave, it's much more involved than that I'm trying to make a kind of visual browser of popular materials from one of our branches from a .csv file. In order to display book covers for a series of searches by keyword, I query the catalog, scrape out only the syndetics images, and then display 4 of them. The problem is that I've hardcoded in a search for 'Drawing', rather than dynamically pulling the correct term and putting it into the catalog query. Here's the work in process, and I believe it will only work in Chrome right now. http://www.natehill.net/vizstuff/donerightclasses.php I may have a solution, Jason's idea got me part way there. I looked all over the place for that little snippet he sent over! Thanks! On Mon, Dec 5, 2011 at 2:44 PM, Walker, David wrote: > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect > > on the client side then I need to make an Ajax request, correct? > > What you probably want to do here, Nate, is simply output the PHP variable > in your HTML response, like this: > > > > And then in your JavaScript code, you can manipulate the text through the > DOM like this: > > $('#foo').html('Cooking'); > > --Dave > > - > David Walker > Library Web Services Manager > California State University > > > -Original Message- > From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of > Nate Hill > Sent: Monday, December 05, 2011 2:09 PM > To: CODE4LIB@LISTSERV.ND.EDU > Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable > > If I have in my PHP script a variable... > > $searchterm = 'Drawing'; > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect > on the client side then I need to make an Ajax request, correct? > What I can't figure out is what that is supposed to look like... something > like... > > $.ajax({ > type: "POST", > url: "myfile.php", > data: "...not sure how to write what goes here to make it 'Cooking'..." > }); > > Any ideas? > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I can't tell what you are requesting via Ajax; I am not sure what you want to hover over; and I am not sure what the relationship of "drawing", "cooking" and hovering is. I am guessing that $searchterm gets submitted to a search, but does it get submitted via ajax? What happens then? Thanks, Cary On Mon, Dec 5, 2011 at 2:08 PM, Nate Hill wrote: > If I have in my PHP script a variable... > > $searchterm = 'Drawing'; > > And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on > the client side then I need to make an Ajax request, correct? > What I can't figure out is what that is supposed to look like... something > like... > > $.ajax({ > type: "POST", > url: "myfile.php", > data: "...not sure how to write what goes here to make it 'Cooking'..." > }); > > Any ideas? > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net -- Cary Gordon The Cherry Hill Company http://chillco.com
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
> And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect > on the client side then I need to make an Ajax request, correct? What you probably want to do here, Nate, is simply output the PHP variable in your HTML response, like this: And then in your JavaScript code, you can manipulate the text through the DOM like this: $('#foo').html('Cooking'); --Dave - David Walker Library Web Services Manager California State University -Original Message- From: Code for Libraries [mailto:CODE4LIB@LISTSERV.ND.EDU] On Behalf Of Nate Hill Sent: Monday, December 05, 2011 2:09 PM To: CODE4LIB@LISTSERV.ND.EDU Subject: [CODE4LIB] jQuery Ajax request to update a PHP variable If I have in my PHP script a variable... $searchterm = 'Drawing'; And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on the client side then I need to make an Ajax request, correct? What I can't figure out is what that is supposed to look like... something like... $.ajax({ type: "POST", url: "myfile.php", data: "...not sure how to write what goes here to make it 'Cooking'..." }); Any ideas? -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] jQuery Ajax request to update a PHP variable
I'm not sure what you're trying to do makes sense. You'd have to write some PHP code to receive the AJAX request and use it to update the variable. There's nothing in PHP that will do this automatically. However, since, I believe, PHP variables are usually only 'in scope' for the context of the request, I'm not sure _what_ variable you are trying to update. I suppose you could update a session variable, and that might make sense. But it doens't sound like that's what you're trying to do it sounds like what you're trying to do is something fundamentally impossible. But if you have a PHP script with "$searchterm = 'drawing';" in it, then that statement gets executed (setting $searchterm to 'drawing') every time the PHP script gets executed. Which is every time a request is received that executes that PHP script. It doesn't matter what some _other_ request did, and an AJAX request is just some other request. You can't use AJAX to change your source code. (Or, I suppose, there would be SOME crazy way to do that, but you definitely definitely wouldn't want to!). On 12/5/2011 5:08 PM, Nate Hill wrote: If I have in my PHP script a variable... $searchterm = 'Drawing'; And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on the client side then I need to make an Ajax request, correct? What I can't figure out is what that is supposed to look like... something like... $.ajax({ type: "POST", url: "myfile.php", data: "...not sure how to write what goes here to make it 'Cooking'..." }); Any ideas?
[CODE4LIB] jQuery Ajax request to update a PHP variable
If I have in my PHP script a variable... $searchterm = 'Drawing'; And I want to update 'Drawing' to be 'Cooking' w/ a jQuery hover effect on the client side then I need to make an Ajax request, correct? What I can't figure out is what that is supposed to look like... something like... $.ajax({ type: "POST", url: "myfile.php", data: "...not sure how to write what goes here to make it 'Cooking'..." }); Any ideas? -- Nate Hill nathanielh...@gmail.com http://www.natehill.net