So I saw a lot of answer on similar question but didn't found how to exactly make it work. I have a lot of functions in query and all of them didn't complete because the html event load the next page. So what I need is how exactly make the html event wait till the jquery check everything that it should check.
so example of jquery is
jQuery.noConflict();
jQuery(document).ready(function($) {
$(document).on("click","input[name=open]", function () {
var login = $("input[name=field1]").val();
var pas = $("input[name=field2]").val();
alert('I call it');
$.post("index.php", {
st: 1,
field1: field1,
field2: field2
}, function(data) {
alert(data);
if ($.trim(data) == 'er') {
alert("Sorry incorrect data");
return false;
}
else
return true;
});
});
});
<div>
<form method="POST" action="index.php?cd=in">
<!----code here --->
<div>
<input name="open" class="field_submit" type="submit" size="7" value="IN" ">
</div>
So the function works fine when there is not line with action="index.php?cd=in". So what happen is just start the function but didn't wait the result and do redirection. So there is couple ways how I can prevent it:
- redirect by jQuery but it not what I need
- is make in HTML file on tag input event
onclick="return function-name();"
But the problem how to correct realize the jquery file function because when I put the function inside the console gives me an error as I the function is not defined. So the problem is how to exactly realize the function in jquery file that it work for onclick event in HTML file. Or if you know other better variant to realize it. Thanks