Click here to Skip to main content
11,934,380 members (30,726 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB jQuery VB.NET

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();
            type: "POST",
            url: "Default.aspx/Save",
            data: "{htmlDiv:'" + htmlDiv + "',postData:'" + postData + "',ImageArray:'" + imageArray+ "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
            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 ;
Posted 28-Jan-13 22:07pm
Rate this: bad
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 ???

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
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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
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