Let make an example of the view code on Django side, which processed the Ajax request and return results if necessary.
return HttpResponse("{'code':'1'}", mimetype='application/json')
Okay, that is what will (successfully) be returned to the calling page; but no registered JavaScript function will be executed. The problem stays on the JSON string and mimetype transfered to response.
When the Json string is defined by using single-quote for string encapsulation, that will not be identified as application/json at client side. That is somehow not very flexible, I think. Therefore, the better return command is:
But really, we should use django.utils.simplejson instead:
...
response_dict = {}
response_dict['code'] = '1'
return HttpResponse(simplejson.dumps(response_dict),
mimetype='application/json')