javascript - Set and change Jcrop image with an ajax query -
i want use jcrop on image obtained , changes ajax query. don't find way script work. @ moment script looks 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 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 jcrop_api undefined in line:
jcrop_api.setimage(resp.img);
any ideas how make work?
in html
<img src="#" id="img_ref"/>
in js
function get_img() { $.ajax({ url: '/ajax/get_img.php', type: "post", data: { idref: $("#idref").val() }, datatype: 'json', success: function(resp) { $("#img_ref").attr("src",resp.imgpath); $('#img_ref').jcrop({ truesize: [100, 100], setselect: [1.0, 1.0, 99.0, 99.0], onchange: jcrop_show_coords, onselect: jcrop_show_coords }); } }); }; $("#submit_data").on('click', function(){ get_img(); });
Comments
Post a Comment