i need pass object within data object it's not working
i use following function found on site, useful, convert form data json
$.fn.serializeobject = function() { var o = {}; var = this.serializearray(); $.each(a, function() { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; };
and need pass object sub-object, it's not working. filters isn't showing in query string parameters in inspector
var filters = $('.filtersform').serializeobject(); $.ajax({ type: 'get', data: {script:'search',page:page,filters:filters}, success: function(data){ } });
see how "filters" missing in picture
can please explain why can't pass object that?
try instead:
$.ajax({ type: 'post', data: json.stringify({ script: 'search', page: page, filters: filters }), contenttype: 'application/json' });
- changed type
get
post
. allow send request body. - stringify data parameter using built-in json object stringify js object json-formatted string. (older browsers may not have built-in object, in case, add using json2.js)
- set contenttype
application/json
. states request-body of type... because stringified json.
Comments
Post a Comment