Reputation: 281
I am running a development server and calling a template view to show me content of "index.html" on my browser. Now I have a button configured in the index.htm file (using JQUERY) to do AJAX get request. How do I include the Django url to do this ?
$(document).ready(function(){
$("#btn1").click(function(){
//alert("Text: " + $("#test").text());
//alert("Text: " );
$.ajax({
url: 'application.json',
dataType: 'json',
success: function( data ) {
alert( "SUCCESS: " + data );
},
error: function( data ) {
alert( "ERROR " + data );
}
});
I want to replace the 'application.json' with a django url which would return me a json response.
here is the return values asscociated with the django view correspoing to the url I wan to include:
response = Response(200, result)
return self.render(response)
Upvotes: 0
Views: 854
Reputation: 131
$.ajax({
url: {% url 'name-of-your-reverted url' %}
...
You can also use view path, just as in doc: Django Doc#url
Upvotes: 1