Reputation: 243
I have a "recruit" button where, when button is clicked via Ajax it has to update the database to "invited" and then the same button should display Invited which is updated to the database. By default the database contains "recruit".
This action happens when button is clicked it updates the database as invited, but another button appears called invited. The recruit button is also there. This is my code.
<div id='submit_wrp'>
<input id='btn_submit' type='submit' class='btn btn-primary active' value= " . $rowchk['recruit'] . "/>
</div> ";
<input type="hidden" type="number" id='REC' value='<?php echo $id ?>'/>
<script>
$('#btn_submit').click(function () {
var name = $('#REC').val();
$.ajax({
type: 'POST',
// url: 'testing.php',
url: 'testing.php?REC=' + name,
data: 'REC=' + name,
success: function () {
// alert("success" + name);
$('#submit_wrp').load(location.href + ' #btn_submit');
///$('#submit_wrp').html(response);
},
error: function () {
alert("error" + name);
}
});
});
</script>
Upvotes: 1
Views: 52
Reputation: 178094
So perhaps you mean
<script>
$(function() {
$('#formID').on("submit",function (e) {
e.preventDefault()
var name = $('#REC').val();
$.ajax({
type: 'POST',
// url: 'testing.php',
url: 'testing.php?REC=' + name,
data: 'REC=' + name,
success: function (data) {
$('#submit_wrp').html(data);
},
error: function () {
alert("error" + name);
}
});
});
});
</script>
<form id="formID">
<div id='submit_wrp'>
<input id='btn_submit' type='submit' class='btn btn-primary active' value= " . $rowchk['recruit'] . "/>
</div> ";
<input type="hidden" type="number" id='REC' value='<?php echo $id ?>'/>
</form>
Upvotes: 1