I just want to use Jcrop on an image that is obtained and changes with an ajax query. But I don't find the way for this script to work. At this moment my script looks like this:
<script>
$(function () {
function Jcrop_show_coords(c) {
$('#roi_X1').val((c.x).toFixed(1));
$('#roi_Y1').val((c.y).toFixed(1));
$('#roi_X2').val((c.x2).toFixed(1));
$('#roi_Y2').val((c.y2).toFixed(1));
};
var jcrop_api; // Holder for the API
$('#img_ref').Jcrop({
trueSize: [100, 100],
setSelect: [1.0, 1.0, 99.0, 99.0],
onChange: Jcrop_show_coords,
onSelect: Jcrop_show_coords
},function(){
jcrop_api = this;
});
function get_img() {
$.ajax({
url: '/ajax/get_img.php',
type: "POST",
data: { idRef: $("#idRef").val() },
dataType: 'json',
success: function(resp) {
jcrop_api.setImage(resp.img);
}
});
};
$("#submit_data").on('click', function(){
get_img();
});
});
</script>
And firebug says that jcrop_api is undefined in the line:
jcrop_api.setImage(resp.img);
Any ideas about how to make it work?