javascript - how do I get AJAX to pass button click to python? -
javascript - how do I get AJAX to pass button click to python? -
i'm novice. pass value html button click on client's browser python script on server send value postgresql db. must missing something. here's javascript, , ajax in html like:
<div class="note" id="(untitled)"> <script type="text/javascript" src="./jquery-2.1.1.js"> $(function () { $("#one").click(function () { $("#one").trigger("click", ["1"]); do_it(1); }); $("#two").click(function () { $("#two").trigger("click", ["2"]); do_it(2); }); }); function do_it(n) { $.ajax({ type: "post", url: "~/script_for_practice_jun20.py", datatype: "json", data: {param: 'n'} success: success }), } )
here's python part using...
def cgi_get_from_ajax(self): import json import cgi info = cgi.fieldstorage() chosen = data["param"].value homecoming chosen def set_choice(self): process = name_of_class() selection = process.cgi_get_from_ajax() entry = [] if selection == '1': entry = [1,0,] else: entry = [0,1] homecoming entry
my deadline approaching. please help me. please. please.
url: "~/script_for_practice_jun20.py",
this server friendly url. jquery cant utilize url ~
sign.
correct url, either relative current page, or absolute root directory.
did got error in console?
javascript jquery python ajax
Comments
Post a Comment