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!

5
  • 2
    dataType isn't the type of data you're sending, it's the type of data returned Commented Nov 12, 2012 at 21:34
  • I did it twice... one time for debugging.. @ahren: ah ok thank you! that make sence! Commented Nov 12, 2012 at 21:37
  • What do you expect to happen when you run your code? What actually happens when you run it? Commented Nov 12, 2012 at 22:04
  • You don't need to stringify to JSON your array. It makes no sense Commented Nov 12, 2012 at 22:21
  • hi zerkms, how would you convert a javascript array to a string then instead of using stringify? I have everything working now. Commented Nov 16, 2012 at 1:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.