Here is an example loading a django template from an input box using ajax .load().
script for load method
$( document ).ready( function() {
$( '#searchSubmit' ).click( function() {
q = $( '#q' ).val();
$( '#results' ).html( ' ' ).load( '{% url "demo_user_search" %}?q=' + q );
});
});
from views.py
return render_to_response( template, data, context_instance = RequestContext( request ) )
vs. script for post method
$.ajax({
url : "/ajaxexample_json",
type : "POST",
dataType: "json",
data : data2,
success : function(json) {
show_results(json);
},
error : function(xhr,errmsg,err) {
alert(xhr.status + ": " + xhr.responseText);
}
});
return false;
});
and from the views.py
return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
I don't know if there is a way for the POST method load a render_to_response template on success, so far I've tried and gotten a 200: error and a pop up (although all of the relevant txt/html is rendered in the pop up).
Is it possible to submit a POST with the .load() function instead?