2016-04-25 108 views
0

我正在使用croppie jquery插件。所有的東西都不錯。調整圖片大小後,我無法從promise對象中獲取數據。請在這裏幫助我。 下面是我點擊按鈕獲取的數據的屏幕截圖。 http://prntscr.com/awi9co如何在jquery中獲取對象值

的代碼如下

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'); 
      } 
     } 
    }); 
}); 
+0

'basic.croppie( '綁定',{ 網址:網址, 幾點:[77,469,280 ,739], })。then(function(){// HERE});'? – Rayon

回答

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'); 
      } 
     } 
    }); 
    }); 

});