I am trying to run a simply backend python method from a jquery script.
The JQUERY
$(document).ready(function(){
$('#btn').click(function(event){
event.preventDefault();
var commit = $("#test_form input[type='radio']:checked").val();
alert(commit);
$.ajax({
type: "POST",
url: "submitted",
data: commit,
success: function(data) {
alert(data["title"]);
$("#status").html(data["title"]);
}
});
return false;
});
$('#update_help').click(function() {
$('#update_info').toggle('slow', function() {
// Animation complete.
});
});
});
In my cherrypy python script, I have the following
@cherrypy.expose
def submitted(self, commit = 0):
cherrypy.response.headers['Content-Type'] = 'application/json'
print"Got here"
#return simplejson.dumps(dict(title="hello", success=True))
return "foo"
The HTML file is like the following
<form id="test_form" method="post">
<li class = "option">
<input type="radio" name="commit" value = "0"/> Option 1
</li>
<li>
Option 1
</li>
<li class = "option">
<input type="radio" name="commit" value = "1"/> Option 2 <br>
</li>
<li class = "option">
<input id="btn" type="submit"/>
</li>
</ul>
</form>
What I notice is that the ajax post never really finds the "submitted" function. The whole page reloads and nothing ever is returned to the ajax post callback. I am sure this has something to do with me doing something wrong with the dispatching but what am I missing?
Thanks