Hi, I would like to post data to PHP via a jquery post after clicking a button using the onsubmit function:
<script>
function Do () {
alert("Before");
jQuery(document).ready(function($) {
$.post("/code.php", {"arg1": "1", "arg2": "2"}, function(response) {
alert('Got this from the server: ' + response);
});
});
alert("After");
}
</script>
<form name="Form1" action="" onsubmit="Do()">
<input type="submit" value="Send">
</form>
Clicking the button the before and after text is shown but not the server response. I tested the code without the button and loading it directly, i.e.:
<script>
jQuery(document).ready(function($) {
$.post("/code.php", {"arg1": "1", "arg2": "2"}, function(response) {
alert('Got this from the server: ' + response);
});
});
</script>
which worked.
Any help is highly appreciated - Thanks,
Toby