The Digg Crew wants to hear your thoughts!
Please take our short survey about Digg and potential feature ideas.
Database-enabled AJAX with PHP...
webreference.com — In this article you'll learn how to create database-enabled Ajax requests using PHP and MySQL. We begin by creating the front-end HTML and JavaScript files used to make requests to the server-side. The requested server-side is a PHP file which bridges the gap between Ajax and a PHP object that connects to a MySQL database and returns results as an
- 923 diggs
- digg it
- LKBM, on 10/12/2007, -35/+6Could you add a few more meaningless buzzwords, please?
- Wootery, on 10/12/2007, -0/+12Very well.
Streamline Web 2.0.
Actually I can only see one buzzword - AJAX.
PHP/SQL/database/JavaScript/HTML aren't really buzzwords, and they have real meaning. - optikschmoptik, on 10/12/2007, -2/+13@LKBM: All those words have well-defined meanings. Most are programming languages or standards, and none are buzzwords. And this article might be useful to people who actually know what they mean. (It looks like a pretty thorough tutorial)
At least check your definitions on Wikipedia before putting on your smartass hat.. - headswine, on 10/12/2007, -0/+1Or just download xajax which has been doing an excellent job of this for some time.
- LKBM, on 10/12/2007, -4/+1"@LKBM: All those words have well-defined meanings. Most are programming languages or standards, and none are buzzwords. And this article might be useful to people who actually know what they mean. (It looks like a pretty thorough tutorial)"
I've been writing 'AJAX' ***** for years, but I don't pretend it's anything beyond a silly buzzword used to mean a million different things. I certainly don't call stuff 'database-enabled AJAX'' Go ahead and tell me that's not buzzword nonsense.
Try reading actual tech resources rather than Wikipedia and you'll see the commentary among geeks--and I don't mean highschoolers using PHP--doesn't use this terminology. Why? Because it's fluff. Yes, people will say 'AJAX', but they use it even when they're not being asynchronous,when they're not using actual XML responses, and so on. This article explains the very basics and fluffs it up with a ridiculously fancy title.
And, no, it's not useful for people who already know anything. And as for checking definition, right back at you. Try checking usage as well. - optikschmoptik, on 10/12/2007, -0/+2LKBM wrote:
"people will say 'AJAX', but they use it even when they're not being asynchronous,when they're not using actual XML responses, and so on."
Are they? OK. Actually, that might be worth knowing for someone. It would have been more helpful than your first comment, which adds nothing and doesn't demonstrate any knowledge or experience. So, forgive me for thinking you're trolling when you frist-post curt sarcastic one-liners.
- Wootery, on 10/12/2007, -0/+12Very well.
- ProtonageNet, on 10/12/2007, -0/+6Atleast it's not amazing.
- r3zonance, on 10/12/2007, -8/+3Damn right this isn't amazing. Pretty useless "done everywhere else, 1 year ago" tutorial.
- fyre2012, on 10/12/2007, -1/+2@r3zonance
Oh, great it's been done before!
Care to post any links to sites which give a similar, yet older and obviously better tutorial? - r3zonance, on 10/12/2007, -0/+1@Fyre2012
Just search for "AJAX tutorial" you find millions of them. The bit that happens in-between the AJAX call and the AJAX callback is EXACTLY the same as normal web development. You just don't return a FULL HTML page, just a partial or some JSON or something like that.
Steps are as follows:
1. Make AJAX Call
2. 'Standard' HTTP Request posted to server via AJAX
3. Server sends back HTTP Response.
4. Handle the response through an AJAX/Javascript callback function.
Steps 2 and 3 are the basic model for any kind of web application.
AJAX itself isn't that much of a leap, once you've seen one tutorial, you've seen them all.
- gibler, on 10/12/2007, -6/+2is this the mystical Web 2.0 technology ??
- LateDeveloper, on 10/12/2007, -13/+1I started doing this about 6 months ago - see www.EuropeanHospitalRegister.com
- manicleek, on 10/12/2007, -2/+9Judging by that site, you needed to stop 6 months ago
- fyre2012, on 10/12/2007, -1/+5hahah, omg that is the ugliest site i've ever seen!
- smur, on 10/12/2007, -1/+0The disclaimer on that site is just precious. See at the bottom of the 'Contact' page. Of course, the text of disclaims is not the developer's fault.
- flash200, on 10/12/2007, -0/+1The site that killed Web 2.0 :)
Wow, those pop-up hints for the buttons are really awful. On FF 1.5 (haven't upgraded to 2.0 yet) and Opera 9, they appear some of the time, inconsistently, for a fraction of a second. That's even more annoying than a website with unwanted pop-up menus that keep appearing and covering the content you're trying to get to.
Also, a full second or two after the page renders, the corners suddenly appear rounded. That's as visually jarring as blinking text.
- atariby, on 10/12/2007, -1/+2That is a painfully unpretty website.
- daroot, on 10/12/2007, -9/+4uhm.. requesting a php file via XMLHttp and sending the response back to the browser? wow i never thought of that! :p *irony*
next on digg: valid markup. why a paragraph cant contain a div *scnr* :> - SVPirate, on 10/12/2007, -10/+4This was like the first thing I did when I started playing with AJAX over aYEAR ago. Dear lords.
- shockertwin, on 10/12/2007, -0/+1Yeah, AJAX has been growing in popularity for a couple years now. Who cares if you have done it for about a year? This is for people who want to start using it.
The tutorial looks excellent. I am gonna bookmark it for future reference. - r3zonance, on 10/12/2007, -0/+1@shockertwin
Google is the easiest way to find AJAX tutorials, not Digg. - HardJeans, on 10/12/2007, -0/+1@r3zonance
Google is the easiest way to find ANYTHING, not Digg.
- shockertwin, on 10/12/2007, -0/+1Yeah, AJAX has been growing in popularity for a couple years now. Who cares if you have done it for about a year? This is for people who want to start using it.
- EbowUK, on 10/12/2007, -2/+3If only there was some sort of search system on the internets where this information could be quickly located. That way Digg could be for news.
Tis but a dream.- somerandomnerd, on 10/12/2007, -2/+7Don't be ridiculous. You'd have to catalogue, like, every page on the internet. That would take up hundreds, thousands- even millions of gigabytes. A googolplex of bytes...
To have the servers required, you'd need something like $2 million a month just for the electricity! Who's going to pay for that? Advertisers? - EbowUK, on 10/12/2007, -0/+1OMGZOR
The internets doesn't run on electricity. The internets runs on the love of humankind. Or twelve hamsters pumped up on steroids. But not electricity!
- somerandomnerd, on 10/12/2007, -2/+7Don't be ridiculous. You'd have to catalogue, like, every page on the internet. That would take up hundreds, thousands- even millions of gigabytes. A googolplex of bytes...
- tagawa, on 10/12/2007, -0/+3Any opinions on the security of this?
- r3zonance, on 10/12/2007, -1/+2It's as secure as any HTTP request.
- mwisconsin, on 10/12/2007, -1/+2It's woefully insecure. The PHP knows the credentials for the database, which therefore means that anyone can make a POST request to mysql_connector.php and get any query results passed backed to them in nicely formatted XML, no questions asked. The PHP supplied doesn't even do any rudimentary referrer checking (even though referrers can be forged).
You could use this, but I'd suggest not using it in the wild. You're just asking to expose all of the critical information in your database to anyone that walks by.
- pkkid, on 10/12/2007, -3/+1What is this Webternet you speak of?
I heard it stands for "Everyone else is smarter than you so shut up and listen to them, or they will 'own' you" - roele, on 10/12/2007, -7/+0I'm bored about this AJAX Hype.
I know of people who did amazing stuff with JavaScript (http://www.neximage.ch/en/home/) in the early millennium in 2001. But since JavaScript isn't confounded with Java anymore an got more acceptance people drive crazy about it...- shockertwin, on 10/12/2007, -0/+0Java and JavaScript are similar because they both have Java in the name. Yeah that must be true.
Javascript would be more popular if you didnt have to make different event methods for 9 different browsers to keep up compatability. Cant wait for the W3C to get at work on it. - r3zonance, on 10/12/2007, -0/+3"But since JavaScript isn't confounded with Java anymore"
It never was.
- shockertwin, on 10/12/2007, -0/+0Java and JavaScript are similar because they both have Java in the name. Yeah that must be true.
- yugnats, on 10/12/2007, -1/+1it may be old to most here but i couldn't find a decent basic AJAX tutorial that actually worked and this worked great for what i needed. kudos to the author.
- tobyjoe, on 10/12/2007, -0/+3Too bad it lacks any sort of degradation and treats JS as a requirement. Pretty amateurish, IMO.
- beejay54, on 10/12/2007, -0/+2Note, you should store your ajax connection objects in an array. Otherwise if you try to send another request before the last one is finished you'll break your connection and cause all sorts of problems. Some will argue that you can build checks for this in your code (which you should) but one thing you can't control is the user refreshing or re-launching the script before the last object completed it's request, storing new connections in an array will prevent this.
- flash200, on 10/12/2007, -0/+3In the Mozilla Ajax tutorial, they use a local variable for the connection object and pass it to the Ajax callback function, rather than using a single global variable. This approach has worked fine for me, though I haven't put it through any rigorous testing.
http://developer.mozilla.org/en/docs/AJAX:Getting_Started
// A simplified partial version of this:
//
function makeRequest(url) {
var http_request = new XMLHttpRequest();
http_request.onreadystatechange = function() { alertContents(http_request); };
...
}
// Callback function
function alertContents(http_request) {
...
}
Is there a downside to this approach versus manually storing the connection objects in an array? It seems simpler this way. - LKBM, on 10/12/2007, -0/+2I used to have beejay54's problem, but then I learned to love closures. I don't understand why all the tutorial writers like to make their xmlhttprequest objects global. It leads right into hacks using arrays or 'associative arrays'.
You don't need it to be global. You're only accessing it via callback. Callbacks have closures. Or maybe I'm completely wrong and these tutorial writers know something I don't. All I know is that globals mess up like you're saying while the way I do it doesn't. flash200 is right on. - r3zonance, on 10/12/2007, -0/+3@flash200
Seems okay, but they do only recommend having 2 active AJAX requests at any time, as for some reason it makes things chug if you have any more. That's on ANY OS and ANY browser. - flash200, on 10/12/2007, -0/+1@r3zonance
thanks for the info
- flash200, on 10/12/2007, -0/+3In the Mozilla Ajax tutorial, they use a local variable for the connection object and pass it to the Ajax callback function, rather than using a single global variable. This approach has worked fine for me, though I haven't put it through any rigorous testing.
- krunkosaurus, on 10/12/2007, -0/+1I really don't know why this is on the front page since I don't think a lot of people will grasp this, but If you truly want to learn AJAX you need to learn JavaScript and the Document Object Model, (DOM is a lot more easy to understand then it sounds, basically JavaScript can manipulate the HTML on the page using the DOM of the page.) I bought Ajax in Action (arguably considered the best guide to AJAX) and was stopped dead in my tracks from lack of DOM/JavaScript knowledge. Then I bought DOM Scripting by Jeremy Keith and it was all clear to me. Coming from a design background I really digg Friends of Ed books. Go to Amazon and look these books up for yourself...
then download them off of BT. I'm so bad. :(
(Hey, I did buy hard copies too, but nothing beats a portable version for quick reference.) - krunkosaurus, on 10/12/2007, -0/+4Also for simple tasks the free JavScript library prototype.js's function ajax.update may be all you need! Even Digg it'self uses a condensed version of this library - just view the source on this page. They also use a really nifty animation addon to Prototype called Scriptaculous. It's seen in the animation when you digg things down - google it for more info.
- architectzero, on 10/12/2007, -0/+3No kidding. This goes with so many things. Sure, it's nice to know how things function beneath the surface, but after you've learned what's going on please go out and take a look at what those who've come before have done. Reuse their work. Especially for such rudimentary foundational stuff like this.
Get the library from here:
http://prototype.conio.net/
Get some education here:
http://www.sergiopereira.com/articles/prototype.js.html
If you are looking for UI elements for use with prototype.js, try:
http://moofx.mad4milk.net/
or
http://script.aculo.us/
Alternatively, take a look at Yahoo!'s free YUI library which provides the plumbing code and the UI code along with significant support from Yahoo:
http://developer.yahoo.com/yui/
- architectzero, on 10/12/2007, -0/+3No kidding. This goes with so many things. Sure, it's nice to know how things function beneath the surface, but after you've learned what's going on please go out and take a look at what those who've come before have done. Reuse their work. Especially for such rudimentary foundational stuff like this.
- reevnat, on 10/12/2007, -0/+1Here is some useful free online books on Ajax and Web Development
http://2020ok.com/3510.htm - bigjules27, on 10/12/2007, -0/+0Even though this may not be the best book on how to use or write in AJAX, but it is an inside look at a rapidly growing technology that will soon be used by millions worldwide.
- jnpowell, on 10/12/2007, -0/+0Great info. Does anyone know how this compares to the methods allowed by Zend's framework (www.zend.com)
- crossers, on 07/17/2008, -0/+0yeah, you can learn many here! very interesting and information article!
http://www.shpe-sac.org
http://www.ocflex.com/
http://www.trgovinca.org
http://www.chasr.org/
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official