It seems to be doing everything right, but when I press the button, nothing happens. POST reception is worth it, but it makes no sense to write.

<script type="text/javascript"> function send() { var be = $('#be').val(); var pe = $('#pe').val(); $.ajax({ type: "POST", url: "/?page=send", data: "be="+be+"&pe="+pe, } }); } </script> <form action=""> <input id="be" type="text" name="be"> <input id="pe" type="hidden" name="pe" value="1"> </form> <input type="button" onclick="send();" value="Отправить" /> 
  • four
    extra} in $ .ajax. learn how to use the console. Yes, and the documentation for jquery will not be superfluous to read, for example, about serialize, ajax. - nörbörnën

1 answer 1

 <form action="/?page=send" method="post" id="myform"> <input id="be" type="text" name="be" /> <input id="pe" type="hidden" name="pe" value="1" /> <input type="button" value="Отправить" /> </form> <script type="text/javascript">//<[!CDATA[ $(document).ready(function(){ $('#myform').on('submit', function(e){ var _self = $(this); $.ajax({ type: _self.attr('method'), url: _self.attr('action'), data: _self.serialize(), success: function(data){ console.log(data); } }); e.preventDefault(); }); }); //]]></script> 
  • Perekrakoberyvili to disgrace. This does not fit my further actions. It was impossible to fix the errors in my code? - Rammsteinik
  • Then just remove the extra bracket, as suggested above, and continue to write without my disgrace and krakozyabrov - dekameron
  • one
    @Rammsteinik, I'll go take this code to the gallery of ugly art, let the people marvel at how ugly you can write an ugly script. - etki