java - PlayFramework Result with Ajax -
according : playframework document 2.0 & playframework document 2.1
i know in play can return:
ok() badrequest() created() status() forbidden() internalservererror() todo
etc...
i send ajax response information in it. unfortunatelly play sends status information, , kind of object not understand. method ok("test message")
sends status , message information. rest of dosnt work. how deal it?
-- edit --
i have ajax method:
$.post($("#assignmentsubmitaddress").text(), { 'units' : submittedunits }, function(response, status, xhr) { shownotyfication(status, response); })
when return ok("test");
in java script variable response
have string test
when return badrequest("test");
in java script variable response have java object. when print variable response
getting object object
.
to send response in json format client send ok containing string :
/** * translate json object json string. */ public static<t> string objtojson(object obj) { objectmapper mapper = new objectmapper(); try{ string json = mapper.writevalueasstring(obj); return json; }catch(java.io.ioexception e){ logger.error(e.getmessage(), e); } return ""; } public static result actions() { object objtosendback = ... return ok(objtojson(objtosendback)); }
you can send wathever want, including html, json more convenient communicating javascript functions.
Comments
Post a Comment