This is what I know on the subject:
We have an ajax function to which we can pass an object with properties like this:
var ajaxRequest = {};
ajaxRequest['type'] = 'POST';
ajaxRequest['async'] = false;
ajaxRequest['datatype'] = 'json';
ajaxRequest['url'] = '/Query/getMydata';
$.ajax(ajaxRequest);
one of these properties is the data parameter which is made of key / value pairs:
ajaxRequest['data'] = {color: 'red' , name: 'Steve' }
I tried to do something like this:
var oData = [];
oData['color'] = 'yellow';
oData['name'] = 'Fred';
ajaxRequest['data'] = oData;
but it does not work.
So my question is: there is an object that I can assign to the 'data' parameter, or I am forced to build the string with concatenation?
EDIT==============
Maybe I did not explain, I know that the method can be created by code like this:
var ajaxRequest = {
type: 'POST',
async: false
....
};
but I'm using objects and properties because I need to make the method 'generic', then I will add the 'if' like this:
function ajaxReq(data){
var ajaxRequest = {};
if( !data.isEmpty()){
ajaxRequest['data'] = data;
}
ajaxRequest['type'] = 'POST';
ajaxRequest['async'] = false;
ajaxRequest['datatype'] = 'json';
ajaxRequest['url'] = '/Query/getMydata';
...
$.ajax(ajaxRequest);
}
ajaxRequest['data'] = {color: 'red' , name: 'Steve' };