(^216) ❘ CHAPTER 7 AJAX
div#addressButtonWrapper {
text-align: right;
}
Finally, the following JavaScript demonstrates a REST request using the ADD method:
$(document).ready(
function()
{
$('select#addressCountry').click(
function()
{
$.getJSON(
'Example 7-9/' + this.value + '.json',
function(json)
{
// Swap out the flag image
$('div#addressCountryWrapper img').attr({
alt : json.name,
src : 'flags/' + json.iso2.toLowerCase() + '.png'
});
// Remove all of the options
$('select#addressState').empty();
// Set the states...
$.each(
json.states,
function(id, state)
{
$('select#addressState').append(
$('')
.attr('value', id)
.text(state)
);
}
);
// Change the label
$('label[for="addressState"]').text(
json.label + ':'
);
}
);
}
);
$('select#addressCountry').click();
$('input#addressButton').click(
function(event)
{
event.preventDefault();
var data = {
country : $('select#addressCountry').val(),
http://www.it-ebooks.info
elliott
(Elliott)
#1