javascript - spring mvc json response to ajax -
javascript - spring mvc json response to ajax -
i have issue json parsing syntaxerror: "json.parse: bad escaped character" while proceeding ajax success : clear ajax code :
$("#ajaxform").submit(function(e) { $.ajax({ url : '/cart/add', type : 'post', contenttype : 'application/x-www-form-urlencoded', info : $(this).serializearray(), datatype: 'json', success : function(content) { $("#result").append(content.addtocartlayer); $.fancybox({ href : '#result', showclosebutton : false, enableescapebutton : false, hideonoverlayclick:false }); }, error : function(xht, status, ex) { console.log("error : " + ex);//json.parse: bad escaped character } });
}
and java code :
@requestmapping(value = "/cart/add", method = requestmethod.post, produces = "application/json") public string addtocart(@requestparam("productcodepost") final string code, final model model, @valid final ausaddtocartform form, final bindingresult bindingerrors, final redirectattributes redirectmodel) { // logic here homecoming controllerconstants.views.fragments.cart.addtocartpopup; }
well story begins adding prodcut cart has specific "size = xl" , "color = reddish ", every thing goes fine until i've changed color value , eg "r'nb" , ajax exception throwen (json.parse: bad escaped character)
i tried add together @responsebody
method have no result .
so question , if need more clarification please tell me
it's because there's invalid character in new color value: "r'nb". json can't handle ' character. please take here: how solve json.parse: bad command character in string literal, in code answers question.
javascript ajax json spring
Comments
Post a Comment