hello, in the following code, why does it work:
var addresses = {"2-avenue-bir-hakiem": "2 Avenue Bir Hakiem", "56-rue-marcel-pagnol": "56 rue Marcel Pagnol"};
but
var addresses = json.val;
does not work
my json output is valid!
{"2-avenue-bir-hakiem": "2 Avenue Bir Hakiem", "56-rue-marcel-pagnol": "56 rue Marcel Pagnol"}
the error i get is
a is undefined [Break on this error] a))();else c.error("Invalid JSON: "+a)...f(d)if(i)for(f in a){if(b.apply(a[f],
<script>
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).attr( "scrollTop", 0 );
}
$( "#companies" ).autocomplete({
source: ";companies",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
$("#address").html(ui.item.id);
$.ajax({
type: 'GET',
url: ';addresses?company=' + ui.item.id,
dataType: 'json',
// process the addresses
success: function(json) {
$('body').append('Response Value: ' + json.val);
var opts = '';
var addresses = {"2-avenue-bir-hakiem": "2 Avenue Bir Hakiem", "56-rue-marcel-pagnol": "56 rue Marcel Pagnol"};
//var addresses = json.val;
$.each(addresses, function(k, v) {
opts += '<option>' + v + '</option>';
});
$('#address').html(opts);
}
}); //end ajax
} // end select
});
});
</script>
what am i missing?
thanks