i have code:
function parsecontent(targetdiv) { $("#"+targetdiv+" > [contentname]").each(function (index) { var data = $(this).attr("contentdata"); if(data != undefined) { alert(data); alert(jquery.param(data)); } }) }
it parses html , looks elements contentname attribute in them. each of those, check see if there attribute contentdata, , if turn json parameters.
it's doing each() fine. 1 alert (the first one) prints:
{reportid : 5}
which correct, fails , in console get:
typeerror: this.replace not function
im pretty sure correct json format. have tried adding quotes {'reportid':5} same error;
any ideas?
it's because $.param expects json object parameter , not string formatted json. if pass this, it's going fail:
var jsonelement = '{"reportid": 5}'; var result = $.param(jsonelement); //throws exception
instead, if do:
var jsonelement = '{"reportid": 5}'; var result = $.param(json.parse(jsonelement));
Comments
Post a Comment