0

Possible Duplicate:
jQuery ajax, how to send JSON in stead of QueryString

I have problems creating a valid JSON string out of a "two dimentional" JavaScript array. If I change the datatype option in the jQuery AJAX request to text I get the success alert.

this is the json-string (from debug in code)

[
   [
      {"x":16, "y":17, "c":"#000000"}
   ],
   [
      {"x":16, "y":17, "c":"#000000"}
   ],
   [
      {"x":16, "y":17, "c":"#000000"}
   ],
   [
      {"x":16, "y":17, "c":"#000000"}
   ],
   [
      {"x":16, "y":17, "c":"#000000"}
   ]
]

this is my code

var pixelqueu =[];

function addtoqueu(x,y,color){//x y colorhex
    var p = [];
    p.push({ "x": x, "y":y,"c":color });
    pixelqueu.push(p);

    if(pixelqueu.length==5){
        var string=JSON.stringify(pixelqueu);//debug
        $('body').append(string);//debug
        sendpixels(pixelqueu);
    }
}

function sendpixels(jsonpixels){
    $.ajax({
        type: "POST",
        url: './proc_pixel.php',
        dataType: 'json',
        traditional: true,
        data: JSON.stringify(jsonpixels),
        success: function (data) {
            alert(data);
        }
    });
}

any help is welcome!

Community
  • 1
  • 1
kasper Taeymans
  • 6,950
  • 5
  • 32
  • 51

0 Answers0