mardi 4 août 2015

How to send image as ajax parameter

I need to save object HTMLImageElement in excel file. I am using highchart and get the image of the chart by getSVG method (Overall process in [http://ift.tt/1JJRGwy])

Now i am trying to write this image into excel file. for doing that i need to pass the image by webservice but i am stuck into overall process. what i have tried is the following:

var svg = chart.getSVG({
                 exporting: {
                     sourceWidth: chart.chartWidth,
                     sourceHeight: chart.chartHeight
                 }
             });             

             var canvas = document.createElement('canvas');
             canvas.height = render_height;
             canvas.width = render_width;

             var image = new Image;
             image.onload = function () {
                 canvas.getContext('2d').drawImage(this, 0, 0, render_width, render_height);                  
                 var data = canvas.toDataURL("image/png")
                 download(data, filename + '.png');
             };



        var dataitem= JSON.stringify({ data: image});

        $.ajax({
            type: "POST",
            contentType: "application/json;charset=utf-8",
            datatype: "json",
            data: dataitem,
            url: "FrontDesign/Sendimage",
            success: function (data) {
                 //code for success
            }
        });

I know JSON.stringify({ data: image}) is not process to pass. Any Suggestion regarding this matter?

Aucun commentaire:

Enregistrer un commentaire