Saturday, 15 June 2013

javascript - In HTML, how do I get AJAX to post button click to .py using jquery and cgi? -



javascript - In HTML, how do I get AJAX to post button click to .py using jquery and cgi? -

i wrote python script inserts info postgresql database. have simple html page couple of buttons, , having hard time posting info button click on client python cgi on server side.

here html, ajax , javascript like:

''<div class="note" id="(untitled)"> <script type="text/javascript" src="./jquery-2.1.1.js"> $(function () { $('#1').on('click', function () { $.ajax({ type: "post", url: "~/pythonscript.py", datatype: "json", data: json.stringify({ 'param': { "1" } }), success: function (response) { alert(response); } }) } $('#2').on('click', function () { $.ajax({ type: "post", url: "~/pythonscript.py", datatype: "json", data: json.stringify({ 'param': { "2" } }), success: function (response) { alert(response); } }) } )

<body> <a href="index2.html"> <button id="1">one</button><br> <button id="2">two</button><br> </a> </body>

here of python looks like:

def cgi_get_from_ajax(self): import json import cgi info = cgi.fieldstorage() chosen = data.value homecoming chosen def set_choice(self): process = name_of_class() selection = process.cgi_get_from_ajax() entry = [] if selection == '1': entry = [1,0,0,0] else: entry = [0,0,0,1] homecoming entry

what doing wrong?

try changing code to:

data: {param: '2'} --- in jquery data["param"].value ---- in python script

this works me. maybe ;)

javascript jquery python html ajax

No comments:

Post a Comment