The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 09:27:00 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Cool technique for JS speed...  (Read 1773 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: February 21, 2008, 12:05:40 PM »

OK this is probably silly and old hat for a lot of you, but I started doing something new today and I like it both for clarity and speed.

If I have a dynamic SELECT in a form, I've used two different methods to populate it: either I ajaxed an answer or had my PHP create JS code that was on page ... something like this:

myArr[0] = 'entry0';
myArr[1] = 'entry1';

... and so forth. It works but is pretty damn ugly- particularly in the case of multiply-dimensioned and shaped arrays. I use JSON when I send data back via AJAX, so I simply combined the two and got nice tight code that I like. After I create <whatever the array is to look like> in PHP, then I json_encode it and place this single line in my outgoing HTML:

brands = eval($theEncodedBrandsString);

What comes out in the final HTML looks like this:

brands = eval({"1":{"name":"Palace Resorts","properties":[{"id":"1","name":"Moon Palace"}]}});

... which is ugly, but wicked fast.

Just a gear turner and ,
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!