Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery VB.NET
Hi,
 
I want to pass an array images though ajax post to a WebMethod. I have written the following code, but I am getting error in that.
 
Please help me in this.
var imageArray= GetImage();
 
$.ajax({
            type: "POST",
            url: "Default.aspx/Save",
            data: "{htmlDiv:'" + htmlDiv + "',postData:'" + postData + "',ImageArray:'" + imageArray+ "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                 alert('success');
            },
            error: function (ex) { return true; }
      });
 
function GetImage() {
    var canvas = document.getElementById("canvasTest");
    var context = canvas .getContext("2d");
 
    //return { index: 0, image: canvas .toDataURL() };
    var imageArray= [];
 
    imageArray[imageArray.length] = canvas .toDataURL()
 
    return canvas ;
}
Thanks,
Posted 28-Jan-13 21:07pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are few problems in the code. First correct them.
 
1. function GetImage() should return imageArray instead of canvas.
 
2. Use array like this.
var imageArray = new Array();
 
3. imageArray[imageArray.length] - What is the imageArray.length ???
 
4.
var context = canvas .getContext("2d");
imageArray[imageArray.length] = canvas .toDataURL()
Extra spaces are there after the selectors.
it should be
var context = canvas.getContext("2d");
imageArray[imageArray.length] = canvas.toDataURL()
 
5. context is declared, but not used.
 
6. htmlDiv, postData not defined.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi ,
 
I have resolved the issue of sending the image array to ajax post by converting the image to string using JSON.stringify the only problem I am having is to parse the image at server side in vb net.
 
Please suggest.
 
Thanks,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100