Estoy haciendo un mosaico de imagenes el cual se nutre de un web service, ent mando llamar al web service por medio de ajax y este me regresa yn json con toda la informacion (url, de la imagen, url de ficha, nombre y descripcion). hasta este punto perfecto, posteriormente pongo todo en su lugar con la funcion attr() de jquery para las imagenes y su src y href para los links pero despues trato de usar las imagenes que puse con attr() y solo si pongo un alert antes de manipularlas me da correctamente los datos si no me devuelve 0 (los datos que uso de las imagenes son width() y height()) espero me puedan ayudar, el codigo es este:
function start(){
$.ajax({
async: true,
type: "GET",
url: "http://"+server+"/ImagesMosaic-war/resources/wsgetimages",
data: encodeURI('request={"base":"db3"}'),
success: function(answer){
json = answer
setAttr();
},
error: function(){alert('Error');}
});
}
function setAttr(){
for(var i=1;i<=7;i++){
$('#f'+i).attr('href',json.result[i-1].tab);
$('#cropbox'+i).attr('src',json.result[i-1].image);
$('#t'+i).text(json.result[i-1].name);
$('#d'+i).text(json.result[i-1].info);
}
minis();
}
function minis(){
//este es el alert
alert($('#cropbox1').width());
$('#cropbox1').Jcrop({
onChange : showPreview1,
setSelect: [ ($('#cropbox1').width()-325)/2.0, ($('#cropbox1').height()-325)/2.0, (($('#cropbox1').width()-325)/2.0)+325, (($('#cropbox1').height()-325)/2.0)+325 ],
aspectRatio: 1
});
}
//esta funcion es la que no hace cuando quito el alert
function showPreview1(coords){
$('#preview1').attr('src',json.result[0].image);
$('#preview1').css({
width: Math.round((325 / coords.w) * $('#cropbox1').width()) + 'px',
height: Math.round((325 / coords.h) * $('#cropbox1').height()) + 'px',
marginLeft: '-' + Math.round((325 / coords.w) * coords.x) + 'px',
marginTop: '-' + Math.round((325 / coords.h) * coords.y) + 'px'
});
}