NYCPHP Meetup

NYPHP.org

[nycphp-talk] Passing JAVASCRIPT variables to PHP

John Campbell jcampbell1 at gmail.com
Tue Apr 1 11:48:45 EDT 2008


On Tue, Apr 1, 2008 at 10:37 AM, tedd <tedd at sperling.com> wrote:
> At 10:18 AM -0400 4/1/08, John Campbell wrote:
>  >
>  >The Ajax method is the best, but will be a real pain in the ass to
>  >implement without a javascript library.
>
>  Why so?

Wasn't it you who suggested an image hack to avoid the complexity of XML-HTTP?

>  I do Ajax all the time with a simple 50 line javascript routine. No
>  large libraries.
>  Check this:
>
>  http://www.webbytedd.com/b/ajax/
>
>  It has one 50 line javascript routine, one 75 line slave php script,
>  and a very simple html.
>

Your code is fine for trivial example pages, but would be a disaster
for a production application.
1) The use of the global 'http' is sloppy and limiting.
2) You need to highlight the selected menu after the callback
completes.  Your coding style will quickly become a mess of
document.getElementByIds().
3) You use browser detection... you should use object detection.  A
try/catch block is a good idea in your case.
4) Your implementation breaks the back button.
5) Clicking the currently selected navigation element causes
unnecessary requests.

With a library, I can fix all of these issues and cut the amount of
code down from 50 lines to 10 lines.  If you were to fix these issues
yourself, your code would grow to more than 250 lines.

-John C.



More information about the talk mailing list