View Single Post
Old 03-05-2006, 04:46 PM   #3 (permalink)
wzeller
Registered User
 
Join Date: Mar 2006
Location: California
Posts: 3
wzeller is on a distinguished road
Smile Wow!

Thanks so much for such an amazingly detailed answer!

I hadn't heard of JSON before, so I looked it up and found a script that would encode my database response to JSON without having to have the whole package installed.

Right now there are only a couple hundred stores, but we hope to soon have thousands, so this is looking more and more like the way to go. At this point, the store can be selected from a pull down. Eventually, the data entry admin will need to type in a store id. But the AJAX code will be unchanged - it will just be an input field instead of a select field.

I'm using a php script on the backend to generate the response. Here's a sample response:

Code:
{"id":"18","storename":"Sample Store Is Us","contactname":"Sammy Sample","phone":"123-456-7890","email":"demo@demo.com","address":"123 Somplace St.","city":"Anywhere","state":"OR","zipcode":"12345","country":"United States"}
Now, in trying to use that with the processResponse function of the script you provided, I can't seem to figure out how to address the values.

I'm certain I'm just missing something fundamental, but I'm at a loss.

I changed the call to processResponse in the handleStateChange function to: processResponse(xmlHttp.responseText) (instead of responseXML). I used an alert(response) within processResponse to verfy that the response string is there, and it is. But then how do I parse it?

Ultimately, I'm thinking the value assignation commands will look something like:

Code:
document.forms.formname.storename.value=xmlhttp.something;
document.forms.formname.contactname.value=xmlhttp.something;
document.forms.formname.address.value=xmlhttp.something;
document.forms.formname.city.value=xmlhttp.something;
document.forms.formname.state.value=xmlhttp.something;
document.forms.formname.zipcode.value=xmlhttp.something;
document.forms.formname.phone.value=xmlhttp.something;
But I need to replace the somethings with, well, something.

It seems I'm a hairs breadth away from getting it to go.

Any further tips?

Thanks again,
Wayne
wzeller is offline   Reply With Quote