Web Development with jQuery®

(Elliott) #1

Making a Server Request (^) ❘ 193


});


// Remove all of the options
$('select#addressState').empty();

// Set the states...
$.each(
json.states,
function(id, state)
{
$('select#addressState').append(
$('<option/>')
.attr('value', id)
.text(state)
);
}
);

// Change the label
$('label[for="addressState"]').text(
json.label + ':'
);
}
);
}
);

$('select#addressCountry').click();

$('input#addressButton').click(
function(event)
{
event.preventDefault();

$.post(
'Example 7-3/POST.json',
$('form').serialize(),
function(json)
{
if (parseInt(json) > 0)
{
alert('Data posted successfully.');
}
},
'json'
);
}
);
}
);

Make the preceding modifi cations, load up the new document, and click the Save button. You


should see something like Figure 7-3.


http://www.it-ebooks.info

Free download pdf