html - Getting database info for a django template with ajax -


i'm new django , ajax, i'm trying following:

  • in html have few "select" elements, , every "select" there button called "view".

  • when click "view" want retrieve database info dependent on option selected in "select" corresponding clicked "view". should done ajax, , want display of said database info in html (without refreshing page obviously).

i understand should add onclick event buttons, , in there send selected option info via ajax, i'm confused following:

  • in such scenario, should use or post? , why?

  • what url contact ajax? should create special url used function (and presumably won't visited user in normal way)?

  • once have ajax call, how should return database info template? assume somehow done in view corresponding url calling? somehow use "success" function in javascript calls ajax?

the relevant question here found 1 django: database object value in template using ajax, doesn't clear of doubts.

for particular use case should use get. if you're using jquery, makes these things easy can use $.get().

create view returns jsonresponse , contact ajax.

yes. you'll use success function in jquery , response contain json serialized output django.

you can either build json object yourself, or use django serializer.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -