'Problem sending request with jquery by onclick event
hello I am sending an ajax request to php but it does not work But my onclick event works fine
this is my code
html code
<span class="btn btn-success btn-sm waves-effect waves-light" onclick="accept_recharge(this, <?= $pay['payment_id'] ?>)">accept</span>
jquery code
<script>
function accept_recharge(sender, payment_id) {
sender = $(sender);
var parent = sender.parentsUntil('.todo-entry').parent();
$.ajax('<?= baseUrl() ?>/admin/acceptRecharge/' + payment_id, {
type: 'post',
dataType: 'json',
success: function(data) {
var response = JSON.parse(data);
new Noty({
type: 'success',
layout: 'topRight',
theme: 'nest',
text: response.message,
timeout: '2000',
progressBar: true,
}).show();
}
});
parent.remove();
}
</script>
php code
public function acceptRecharge($payment_id)
{
AdminModel::acceptRecharge($payment_id);
echo json_encode(array('status' => '1', 'message' => 'recharge success'));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|