I’m trying to send two values to a python script, if a certain button is pressed.
But there is a problem:
With alert("test"); everything works perfectly. But without it, there is nothing send.
I think this is a kind of timing problem, but i cannot really think about what is the problem.
Strange is, that i even can put the alert in front of the ajax function (but still in the $("#submit").click part) and it works perfectly.
<script type="text/javascript" src="./jquery-1.4.4.min.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function(){
$("#submit").click(function(){
jQuery.ajax({
type: "POST",
url: "../../../cgi-bin/testCgi.py",
data: {"nick" : $("#nick").val(), "msg" : $("#msg").val()},
success: function (msg) {
alert("Data: " + msg);
}
});
alert("test");
});
});
/*]]>*/
</script>
If
#submitis a link element<a href="...">or a form button, you will need to cancel the default action.If you do not do this, then the page follows the link, or submits the page.