jquery - accessing list sent from server as JSON object -
How to use a menu in a list sent as a jazan object on the templates received in the AJAX callback function.
The code is as follows:
views.py def showfiledata (request): open ("/ home / tazim / webexample / test.txt") f: List = f .readlines () f.closed return_dict = {'filedata': list} json = simplejson.dumps (return_date) HttpResponse (json, mimetype = "application / json")
.html in template showfile:
& lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" src = "/ jquerycall /" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("button"). Click (function () {$ .ajax ({type: "POST", url: "/ showfiledata /", datatype: "Jason" Success: Function (data) {var s = data.filedata; $ ("# someid"). Html (s);}});});}); & Lt; / Script & gt; & Lt; / Top & gt; & Lt; Body & gt; & Lt; Form method = "post" & gt; & Lt; Button type = "button" & gt; Click me & lt; / Button & gt; & Lt; Div id = "someid" & gt; & Lt; / Div> & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html>
Comments
Post a Comment