Tell me how to do? There is 1 chakbox, as when selecting / unchecking the checkbox, immediately send a request to the database without refreshing the page and without an additional submit button, and the 1 id variable must be passed to the handler.
Closed due to the fact that the question is not clear to the participants of Streletz , Kromster , HamSter , Bald , cheops 3 Oct '16 at 5:32 .
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 .
- There are a lot of examples in Google. Please try to write more detailed questions. Look at the examples in Google, read what ajax is and how it works, the types of ajax events, ajax requests and write down what exactly is not clear to you how to do. - Alex
|
1 answer
In the test.php file, check $_POST["type"] and update the data in the database.
$("#checkbox").on("click", function() { var type = $("#checkbox").is(":checked") ? 'yes' : 'no'; $.ajax({ url: 'test.php', type: 'POST', data: { type: type }, contentType: false, cache: false, processData: false, success: function(data, textStatus, jqXHR) { alert('Запрос выполнен'); }, error: function(jqXHR, textStatus, errorThrown) { } }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" name="checkbox" id="checkbox" value="yes"> <label>тест</label> - Tell me, if I need to pass the variable id for the checkbox, how to do it? - Maxim S
- @ Maxim if you need to pass the id of a third-party element, then
var id = $("#element").attr("id");anddata: { type: type, id:id }- Alex - thanks for the help. - Maxim From
|