I have this form with two radio buttons that select ‘1’ or ‘0’.
<form id="f13form">
<p class="info"><?php echo $row["fortress_13"]; ?></p>
<span class="is-size-7 tag is-link"> 13:00 UTC</span>
<label class="radio"><input type="radio" name="for13" value="1"/> Yes</label>
<label class="radio"><input type="radio" name="for13" value="0"/> No</label>
</form>
and then the AJAX function to pass data to php file and then update a MySQL table
$('#f13form input').on('change', function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "update_events_week.php",
data: $('#f13form input').serialize(),
cache: false,
contentType: false,
processData: false,
success: function(){
alert("Updated");
}
});
});
I found how to select the right form I want to handle (there are more in the page) but I’m confused about how to get the ‘1’ or ‘0’ from the form and send to php file.
2
Answers
HTML
JQUERY
https://jsfiddle.net/vp1r9xug/
Your ajax request has no content-type set, so your PHP script will not know how to interpret the data. Remove
contentType: false,
so that the content type will be set, also removeprocessData: false,
.Preventing the default action of the radio button change event may not be desirable either.