I have following jQuery code and it works fine and I am able to deserialize it in the server properly.
But when I tried to create a variable and pass that as a JSON object, it didn’t work. (The commented code didn’t work. The values didn’t reach the server correctly).
Reference: http://www.json.org/js.html
How can we define the variable correctly for the JSON object?
$(".searchCostPages").click(function () {
var url = '/SearchDisplay/' + 'TransferSearchCriteria';
//var searchCriteria = {};
//searchCriteria.Accrual = "A";
//searchCriteria.Brand = "B";
//$.getJSON(url, {searchCriteria: searchCriteria
//}, function (data) {
// if (data.length) {
// alert('Success');
// }
//});
$.getJSON(url, {
"Accrual": "A",
"Brand": "B"
}, function (data)
{
if (data.length)
{
alert('Success');
}
});
});
Working - Network Header:
Not Working - Network Header:
UPDATE
Following code worked here. Also refer jQuery Ajax parameters are not formatted properly
var searchCriteria = {};
searchCriteria.Accrual = "A";
searchCriteria.Brand = "B";
$.getJSON(url, searchCriteria
, function (data) {
if (data.length) {
alert('Success');
}
});