私は<input type='submit'/>
のボタンとaction='updateEstado.php'
の4つのフォームを持っています。また、ボタンをクリックすると起動するjQueryコードがあります。私は、コンソール・ショーこのメッセージをupdateEstado.phpを起動したときに今event.preventDefault();
JQUERY + PHP POSTは値を送信しません
:
私はこれを削除した場合、私はこの新しいラインとjqueryのコードを更新した
<!-- CHANGE STATUS MODAL MENU -->
<div class="modal fade" id="change" tabindex="-1" role="dialog" aria-labelledby="change" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">CANVIAR ESTAT</h3>
</div>
<form action="updateEstado.php" method="post">
<div class="modal-body">
<div class=" text-center">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center">
<input type="submit" id="cambiarestado" class="btn btn-modal-estado" style="background-color:YellowGreen; color:white;" value="ACTIVAT">
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<input type="submit" id="cambiarestado" class="btn btn-modal-estado" style="background-color:Tomato; color:white;" value="PENDENT MIQUEL ALIMENTACIÓ">
</div>
</div>
<div class="row ">
<div class="col-md-12 text center">
<input type="submit" id="cambiarestado" class="btn btn-modal-estado" style="background-color:SkyBlue; color:white;" value="PENDENT ADDCOM">
</div>
</div>
<div class="row">
<div class="col-md-12 text center">
<input type="submit" id="cambiarestado" class="btn btn-modal-estado" style="background-color:Gray; color:white;" value="DESACTIVAT">
</div>
</div>
<div class="row">
<h5 id='codigosSeleccionados'></h5>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$('#cambiarestado').click(function(){
event.preventDefault();
// Get the value of the input fields
var inputvalue = $(this).attr("value");
// Send Ajax request to updateEstado.php, with value set as 'input' in the POST data
$.post("updateEstado.php", {estado: "DESACTIVAT", codigo: "38"});
alert(inputvalue);
});
</script>
行:$.post("updateEstado2.php", {estado: "DESACTIVAT", codigo: "38"});
表示メッセージが表示されなくなります。これが問題であることは明らかです。ソリューション?私はしない...
:
これをarchieveする最も簡単な方法は、隠された入力を使用することです。代わりに 'class'をトリガーとして使用してください。 – Rasclatt
ボタンを送信すると、そのままフォームが送信されます。あなたのjQueryコードは決して実行されません。フォーム自体にonsubmit関数を追加する必要があります。http://www.w3schools.com/jsref/event_onsubmit.aspさらに、IDは一意でなければなりません。 – Danmoreng
はい、jqueryに警告メッセージを表示できるので、コードが実行されます。 – ruzD