Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
Old 08-28-08, 02:17 PM   #13
fivefeet8
Ngemu Mod
 
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
Default Re: AJAX FTW!!!

Quote:
Originally Posted by t3hl33td4rg0n View Post

User input >> XMLHttpRequest (fxhr) >> PHP Script (Make JSON output in plain text and send to fxhr.responseText) >> js script, parse JSON into DOM >> output to targeted elements via JS.
You'll need to use the Javascript eval(); function to evaluate the JSON string into a javascript object. Essentially, you'll:

Code:
// if responseText is {'state':'CA','zip':'93727'}
var jsobj = eval(fxhr.responseText);

// jsobj.state ==  'CA'
// jsobj.zip == '93727'
JSON Strings can also evaluate into arrays of variables and objects.
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w]
fivefeet8 is offline   Reply With Quote
Old 08-29-08, 11:18 AM   #14
t3hl33td4rg0n
Dethklok Returns!
 
t3hl33td4rg0n's Avatar
 
Join Date: Dec 2004
Location: Kent, OH
Posts: 2,142
Send a message via AIM to t3hl33td4rg0n Send a message via MSN to t3hl33td4rg0n Send a message via Yahoo to t3hl33td4rg0n
Default Re: AJAX FTW!!!

I guess I shouldve read more about that in my book. The Javascript book I have mostly covers general DOM stuff, and very little on AJAX XML and JSON.

Actually, that little snippet is the perfect example, thanks!
__________________


Intel QX9650 @ 3.83GHzXFX 780ieVGA GTX 560Ti8GB GSkill DDR800Creative Sound Blaster X-Fi Titanium PCI-ESeagate 1.5TB . 4x Samsung 2TB

Quote:
Originally Posted by MowTin View Post
....it's so clear how government makes things worse not better...
t3hl33td4rg0n is offline   Reply With Quote
Old 08-29-08, 11:40 AM   #15
t3hl33td4rg0n
Dethklok Returns!
 
t3hl33td4rg0n's Avatar
 
Join Date: Dec 2004
Location: Kent, OH
Posts: 2,142
Send a message via AIM to t3hl33td4rg0n Send a message via MSN to t3hl33td4rg0n Send a message via Yahoo to t3hl33td4rg0n
Default Re: AJAX FTW!!!

Quote:
Originally Posted by fivefeet8 View Post
And also because newer versions of PHP includes a JSON encoding/decoding extension written in C that is super fast at taking any object in PHP and changing it into a JSON string for echoing back to the javascript.
You're referring to?
Code:
json_encode($array);
Just looked it up, this is gonna make things much easier! For the past few days I've procrastinating and loathing how everything was going to be compiled and parsed back and forth lol!
__________________


Intel QX9650 @ 3.83GHzXFX 780ieVGA GTX 560Ti8GB GSkill DDR800Creative Sound Blaster X-Fi Titanium PCI-ESeagate 1.5TB . 4x Samsung 2TB

Quote:
Originally Posted by MowTin View Post
....it's so clear how government makes things worse not better...
t3hl33td4rg0n is offline   Reply With Quote
Old 08-29-08, 11:56 AM   #16
fivefeet8
Ngemu Mod
 
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
Default Re: AJAX FTW!!!

Quote:
Originally Posted by t3hl33td4rg0n View Post
You're referring to?
Code:
json_encode($array);
Just looked it up, this is gonna make things much easier! For the past few days I've procrastinating and loathing how everything was going to be compiled and parsed back and forth lol!
Yep. That PHP function will encode any array or objects into a JSON string. There was also a php version of the json_encode functions for use in servers which don't have the newest version of PHP installed, but it was far far slower than the C extension. Remember though, that the JSON encoding will only encode data, not functions. Functions do not get encoded back into Javascript object functions.

Also, json_encode will only encode public object variables. Any object variable that is not public will be left out of the encoding.
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w]
fivefeet8 is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:18 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.