croppie插件使用ajax / innerHtml内容无法正常工作

时间:2017-10-29 12:55:14

标签: javascript jquery ajax

我正在使用croppie插件,但在使用ajax / php覆盖内容时效果不佳(结果显示为innerHtml)。我该怎么办?请帮帮我!

详细了解croppie:https://foliotek.github.io/Croppie/

data.php的内容:php和html代码的编译

<?php
if(isset($_POST['id']) && $_POST['id'] == 1){
?>
<div id="upload-demo" style="width:350px"></div>
<strong>Select Image:</strong>
<br/>
<input type="file" id="upload">
<?php
}
?>

我的代码:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="http://demo.itsolutionstuff.com/plugin/croppie.js"></script>
<link rel="stylesheet" href="http://demo.itsolutionstuff.com/plugin/croppie.css">
</head>
<body>

<div id="div1"></div>

<button>Get External Content</button>
<script>
$(document).ready(function(){
        $("button").click(function(){
            $.ajax({
                    type: 'get',
                    url: 'php/data.php',
                    data: {
                            id: '1'
                    },
                    success: function(response) {
                            document.getElementById("div1").innerHTML = response;
                    }
            });
        });
});

$uploadCrop = $('#upload-demo').croppie({
    enableExif: true,
    viewport: {
        width: 200,
        height: 200,
        type: 'circle'
    },
    boundary: {
        width: 300,
        height: 300
    }
});
$('#upload').on('change', function () {
    var reader = new FileReader();
    reader.onload = function (e) {
        $uploadCrop.croppie('bind', {
            url: e.target.result
        }).then(function(){
            console.log('jQuery bind complete');
        });
    }
    reader.readAsDataURL(this.files[0]);
});
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您的问题将通过以下代码解决:

/*@
 requires \valid(v+(0..n-1));
 requires n > 0;
 assigns v[0..n-1];
 ensures \forall integer q; 0<=q<=n-1 ==> v[q]==(unsigned char)0;
*/
static void make_zero( unsigned char *v, size_t n ) {

  unsigned char *p = (unsigned char*)v;

  /*@
    loop invariant 0 <= n <= \at(n, Pre);
    loop invariant p == v+(\at(n, Pre)-n);
    loop invariant \forall integer j;  0 <= j < (\at(n, Pre)-n) ==> v[j] == (unsigned char)0;
    loop assigns n, p, v[0..\at(n, Pre)-n-1];
    loop variant n;
  */

  while( n-- ){
    *p++ = 0;
  }
}