如何在jquery中获取对象值

时间:2016-04-25 06:41:55

标签: javascript jquery

我正在使用croppie jquery插件。所有事情都很顺利。调整图像大小后,我无法从promise对象获取dataurl。请帮助我。 这是我点击按钮时获得的数据的屏幕截图。 http://prntscr.com/awi9co

守则在

之下
var basic = $('#divLoadLogo').croppie({
    viewport: {
        width: 150,
        height: 50
    },
    enableOrientation: true
});
basic.croppie('bind', {
    url: Url,
    points: [77, 469, 280, 739],

});
$("#SaveResizeImage").click(function() {
    var CanvasData = basic.croppie('result', 'canvas'); //This contains the promise object
    $.ajax({
        type: 'POST',
        url: '/User/SaveResizedCanvasImage',
        data: '{ "imageData" : "' + CanvasData + '" }',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        async: false,
        success: function(data) {
            if (data.success) {

                alert('image is resized');
            }
        }
    });
});

1 个答案:

答案 0 :(得分:0)

尝试:

var basic = $('#divLoadLogo').croppie({
    viewport: {
        width: 150,
        height: 50
    },
    enableOrientation: true
});
basic.croppie('bind', {
    url: Url,
    points: [77, 469, 280, 739],

});
$("#SaveResizeImage").click(function() {
    basic.croppie('result', 'canvas').then(function(CanvasData){
    $.ajax({
        type: 'POST',
        url: '/User/SaveResizedCanvasImage',
        data: '{ "imageData" : "' + CanvasData + '" }',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        async: false,
        success: function(data) {
            if (data.success) {

                alert('image is resized');
            }
        }
    });
    });

});