I\'ve been having problems with this code I had spent the last 3 hours digging around and trying to find an answer. As I wasn\'t successful, I will just post the code and as
If you're working with JSON-enabled .NET WebServices/WebMethods... my tips are:
Be very careful with web.config configuration. Use it to enable big parameters, POST method and JSON.
Use a framework to handle Object serialization e deserialization. I would recommend NewtonSoft's Json.NET.
I don't think ASP.NET automagically do it for you, your parameters are always strings. You should take that strings, deserialize it and turn it to an array of objects.
Try passing the data as a string, not an object, ie:
$.ajax( { ... data : '{ a: 2, b: 3 }', ... } );
The reasoning for this is that if you specify an object as data then jQuery serializes the data using query string format, whereas the server is expecting JSON format directly.
This happens despite telling jQuery to use JSON as the data type - it seems to only relate to the result, not the request payload sent to the server.
Everything else you have there looks correct to me.
Although this is an older post I thought I would contribute. I have been sending an associative array same idea an the accepted post I just find it easier to write.
Javascript
postData[0] = 'data!';
postData[1] = 'moar data!';
postData[2] = 'and some data';
$.ajax({
type: 'POST',
url: 'postUrl',
data: { data: postData },
});
PHP
$data = $_POST['data'][0];
$moar_data = $_POST['data'][1];
$and_some_data = $_POST['data'][2];