i created this ajax and i wanted to call it using an alert to test if everything was fine, but no matter what i did i couldnt ( i tried changing .click to .onclick and to on(“click”, function (){} and nothing worked, so i will show my ajax, where my js is being called and where my ajax is going
my scripit down here
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"
src="script.js"
></script>
this i where my button is( on the same page as my js scripit being called)
echo '<button id="likeB" type="button">Like</button>';
and here it’s my ajax
$('#likeB').click(function(evento){
console.log('a')
alert('ok');
evento.preventDefault();
var likes = 1
$.ajax({
url: 'textover.php',
method: 'POST',
data: {InsertLike: likes},
dataType: 'json'
}).done(function(resultado){
console.log(resultado)
});
});
and i also have a PHP error this one: Warning: Undefined array key “InsertLike” in C:xampphtdocsjamelumn1129pagestextover.php on line 12
probably because it’s reciving no resault because of ajax right?
line 12 is this one:
$InsertLike = $_POST[‘InsertLike’];