$.post(“libarary/bin/new”, { “That wasn’t so bad” : “Nope” } function (data) { }, “json” );

So, I’ve been working on a new PHP project that’s been giving me a lot of fun, and I must confess that I was always scared to work with AJAX because quite frankly it seems really complicated from the outside. When you’re learning PHP and XHMTL, and all that jazz we always seem to be taught that the pinnacle of the internet is using Javascript to bind it all together. Now for simple stuff, Javascript is great. It smells a lot like a freight train of Perl ran into .net or something similar.

One of the things that’s always scared me about the whole Ajax thing was I figured I wouldn’t have any hope of making since of it all. That was until I realized how god awful simple JQuery actually made things.

I heard about the library before, but I had never actually tried to use it. I figured that it was going to be complicated as sin. That the PHP needed to pass XML would make me want to vomit. So much to my surprise, when I discovered that JSON could be passed back and forth and JSON was little more then a glorified multidimensional array (to the common man, I’m sure it’s quite fancy)

I setup a PHP page, give it some settings to listen for (using Jquery’s $.post function), query the database based on what it was sent, and then all I had to do was encode that data in an array and feed that to something as simple as echo json_encode($array);?

Holy balls if someone had told me it was this easy I would have been doing this so much earlier. Now I’m still stumbling as I start to have to learn where it’s good to summon a new page verses where it’s ok to simply make a JSON call and replace an element of the page. How that affects user navigation, etc. But it’s been a lot more fun than I thought it would be. Honestly the toughest part has been deciding what kind of views I want in the database for the various query’s that I need to run.

I guess I’m just putting this out here to say if you were hesitant about starting to do “AJAX”, it really is NOT bad. It’s incredibly simple with the jquery library and had I know how much simpler like I said I would have been doing this 5 years ago.

Really the lesson to take away from this is don’t be afraid to try something new, it might just surprise you.

Advertisements
This entry was posted in Code and tagged , , . Bookmark the permalink.

One Response to $.post(“libarary/bin/new”, { “That wasn’t so bad” : “Nope” } function (data) { }, “json” );

  1. Andrew K says:

    I’m not using Jquery, but Ajax (and postbacks in particular) make me rage more than detective shows incorrectly using tech-speak.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s