Please tell me how to transfer the contents of these inputs to php without buttons and reloading the page. It seems as possible through ajax. I tried, nothing happened.

<input type="text" name="step1" /> <input type="text" name="step2" /> <input type="text" name="step3" /> <input type="text" name="step4" /> <input type="text" name="step5" /> 

Closed due to the fact that the essence of the question is incomprehensible by the participants Igor , Enikeyschik , Dmitry Kozlov , aleksandr barakin , yolosora Nov 26 '18 at 10:54 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And how without a button you are going to determine that it’s time to send the form to the server? After what event should this happen? - Vincent
  • $ ('# text'). bind ('input', function () {$ .ajax ({url: '/ajax.php', method: 'post', dataType: 'html', data: {text: $ ('#text'). val ()}, success: function (data) {$ ('# result'). html (data);}});}); - Anton Milevsky
  • it just doesn't work for some reason - Anton Milevsky

1 answer 1

First, you lack the value attribute on the inputs. Secondly, in any case, you need some kind of action (even if implicit) to send. In the simplest case, these inputs are part of the form (inside the <form> ), and after submitting (by button or $_REQUEST else) they will become $_GET / $_POST and $_REQUEST in php.

Alternatively, without reloading the page, hang up sending to any event (not necessarily click on the button), which one you need, and then collect the field values ​​from the form using javascript and send it one way or another. For simplicity, you can use jQuery like this:

 function submitForm(){ var form = $("селектор формы"), url = form.attr("action"), formData = form.serializeArray(); $.post(url, formData).done(function (data) { console.log(data); }); } $("какой-то селектор").on("какое-то событие", submitForm); 

PS: use on instead of bind . And sending input in the text field to the input event without debouncing / throttling can force your interface to lag and create excessive load on the backing. The essence of debouncing / throttling is to make rarer data sending, i.e. not right after each character entered / deleted, but with a pause after the last event ( debouncing ) or just once in a while ( throttling ).