-1
This basic code below will be used to filter via POST and jQuery a SELECT
on a PHP page.
The form sends to the same page, jQuery receives and sends to PHP, which receives via $_POST["campanha"];
.
The page shouldn’t be giving refresh but this is happening. Can anyone help me with this mistake, please?
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script type="text/javascript">
$(function(){
$("#bot_enviar").click(function(){
event.preventDefault();
var varCampanha = $("#campanha").val();
$.post('teste.php', {
type:"POST",
campanha: varCampanha
}, function(response){
alert(campanha);
});
});
})
</script>
</head>
<body>
<form action="" method="post" id="bot_enviar">
<select name="campanha" name="campanha">
<option value="1">1</option>
<option value="3">3</option>
</select>
<br>
<input type="submit" >
</form>
Campanha: <?php echo $_POST["campanha"]; ?>
</body>
</html>