Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Learning AJAX by example? 1

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
Gents;

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]
 
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
Code:
$(function(){
   $("select").change(function(){
       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
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top