Why isn't my callback function for this Jquery .post working?
-
27-03-2021 - |
문제
Here is the code for the jquery:
<script type="text/javascript">
$(document).ready(function(){
$('#room').submit(function(){
$.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
alert(1);
$('#llama').append(data);
console.log('working');
});
});
return false;
});
</script>
The function part does not seem to be working. The PHP code on the backend/CreateRoom.php seems to work fine(the code updates a PHP database) works fine, it just doesnt update the div, or do anything I put in the function. Help?
해결책
Looks like you are returning false
on document ready. I think you want that on submit.
$(document).ready(function(){
$('#room').submit(function(){
$.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
alert(1);
$('#llama').append(data);
console.log('working');
});
return false;
});
});
or prevent default:
$(document).ready(function(){
$('#room').submit(function(event){
event.preventDefault();
$.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
alert(1);
$('#llama').append(data);
console.log('working');
});
});
});
제휴하지 않습니다 StackOverflow