Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Learning AJAX by example?

Learning AJAX by example?

Learning AJAX by example?


I've been struggling with this for literally months and cannot seem to get a handle on it.  I am a seasoned developer but not that familiar with js.  I've spent the last several days (yes - many, many days over months) searching for examples and have found many but not what I believe would be a simple solid example.

I am trying to use the onchange attribute of an html <select> statement so the selected item will trigger a js script to communicate with a server via XMLHttpRequest then accept the returned content and populate a target select section.  
I do have a working host module that returns a json encoded string with the desired content.  In fact, here it is:

{"*A":"*ALL","C5":"Cash 5","L":"Classic Lotto","P3E":"Play 3","P3M":"Midday 3","P4E":"Play 4","P4M":"Midday 4","PB":"Powerball"}

I've played with many many variations of js code in my test php program/js content without success.

I am HOPING that someone here can reference a simple set of js scripts that will:

1) generate an XMLHttpRequest based on the value selected by the user on the first select/option set;
2) parse the returned json content and re-populate the target select/option set then enable the select itself.

Someone, somewhere must have this logic or at least know where to find good examples?

I do have several javascript books as well as access to much online js content.  And, an example is worth a thousand words (or days in my case).

Thanks to ANYONE who can provide this example or a reference thereof.

B ponder      

RE: Learning AJAX by example?

all the js libraries have an implementation of ajax: jquery, dojo, prototype, moo tools.

I use jQuery and ajax is can be as simple as


       var value = $("option:selected").val();
       var url = "the/url.php?key=" + value;

       $.post(url, function(data, status){
           var json = JSON.parse(data);
           //do work with json

Jason Meckley
Specialty Bakers, Inc.

FAQ855-7190: Database Connection Management

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close