This is what I doing to build the data:
for (var i = args.length; i < args.length; i += 2) {
if (args.length != 0) args += ',';
args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
}
This is how I am calling:
$.ajax({
type: "GET",
url: "/blog/GetPosts",
//data: "{" + args + "}", <- gives 500 in 1.6 but works in 1.3
data: "app=blog&id=100&page=2&pagesize=10", <- this works
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (res) {},
error: function (xhr, status, error) {}
});
How to build the data with multiple parameters and pass to controller?
I need to loop and build the data since I have variable length of parameters.
Note that this works:
data: “app=blog&id=100&page=2&pagesize=10”
But I can have &abc=something in the data itself which will be treated as another parameter.
Thanks for reading
Don’t create the string representation of an object, create an object instead. Also, your loop is wrong, so it would not get the values from the array properly.
Now use the variable in the call: