You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A solution for returning JSON to where Sijax.request() is called in javascript:
Python setup:
# Extend BaseResponseclassSijaxJson(sijax.response.BaseResponse):
defjson(self, data):
#return dataparams= {"json": data}
returnself._add_command("json", params)
# UsageclassMySijaxHandlers(object):
@staticmethoddefget_json(obj_response, obj):
try:
db_result=MyTable.objects.get(id=obj['id']) # example using MongoEngineresult_json=db_result.to_dict() # jsonify objectobj_response.json(result_json) # return using new methodexceptExceptionase:
obj_response.html('#feedback', "%s"%e)
# Target extend class in your post methodg.sijax.register_object(MySijaxHandlers, response_class=SijaxJson)
Javascript:
// the key was in understanding that the "success" method could be over-riddenSijax.request('get_json',[args],{data: {csrf_token: "token_here"},success: function(response){console.log(response[0].json);}});
jQuery.ajax could be used directly, of course, but by extending the Sijax BaseResponse server side, it is easy and convenient to simply target my existing custom Sijax handlers.
The text was updated successfully, but these errors were encountered:
A solution for returning JSON to where Sijax.request() is called in javascript:
Python setup:
Javascript:
jQuery.ajax could be used directly, of course, but by extending the Sijax BaseResponse server side, it is easy and convenient to simply target my existing custom Sijax handlers.
The text was updated successfully, but these errors were encountered: