Some time now that I am struggling with this function. Here is an example:
HTML example code:
<form method="POST">
<label>Input 1:</label><br/>
<input type="text" name="Input1" id="Input1"/><br/>
<input type="submit" name="Login" value="Login" id="Login"/>
</form>
PHP example code (script.php):
if(isset($_POST['Input1Php']))
{
$Input1 = $_POST['Input1Php'];
if($Input1 == "Random Condition")
{
echo "All good";
}else
{
echo "Hell no!";
}
}
jQuery example code (I also tried with .submit(), doesn’t change anything):
$('#Login').click(function()
{
var Input1JS = $('#Input1 ').val();
if("Something"=="Random Condition")
{
$.post('script.php',{Input1Php:Input1JS},function(data)
{
if(data=="All good")
{
Show me that
}else
{
Show me this
}
});
}else
{
Just don't do anything
}
});
This script works find with .keyup, etc but when I change it to click or submit, it just doesn’t do anyhting. I don’t understand why. Am I missing something? Does $.post just don’t work with those events?
PS: Please, don’t change the $.post to something else. My point is to understand how or if THIS function works with those events.
Having that your question lacks some information, it’s possible that your page is posting back so it doesn’t wait for
$.postto return. Try changingto
and see what happens.