I managed to solve, I’ll leave the method in case someone is looking for how to do
Javascript/Ajax function
function curti(codigo,identify){
$.ajax({
url:("ajax/curtir.php"),
type: "POST",
data: {"udid": codigo},
success:function(data){
$("#"+identify).html("("+data+")");
}})}
PHP function
<?php
header('content-type: application/json; charset=utf-8');
include('../class/mysql_crud.php');
$id = (isset($_POST['udid'])) ? (int)$_POST['udid'] : 0;
$db = new Database();
$db->connect();
$db->sql("SELECT * FROM musicas_home WHERE guid = $id");
$res = $db->getResult();
foreach($res as $output){
$curtirv = $output["curtir"];
}
$curtir = ($curtirv + 1);
$db->update('musicas_home',array('curtir'=>$curtir),'guid='.$id);
echo json_encode($curtir);
Button calling function with onclick
echo "<button id='$guidcurti' role='button' onClick='curti($guid,$guidcurti)' class='btn btn-default fa fa-thumbs-o-up'>($curtir)</button>";
Surely there is a way to improve a lot, who wants to edit the will.
you have error in javascript or php ? specify better your doubt post your return what you are getting in ajax ? you have already looked at your browser debug if you have any error in chome is just hit the F12 and go on console
– user28266
in fact nothing happens, I do not understand much of ajax I want to know a correct way to carry out this operation
– Jefferson Mello Olynyki
jquery.js:9664 POST http://kingofeletro.com.br/3/[Object%20Object] 404 (Not Found)send @jquery.js:9664ajax @jquery.js:9215m.(Anonymous Function) @jquery.js:9361likes @ (index):258onclick @ (index):270 13owl.carousel.min.js:1 Uncaught Typeerror: Cannot read Property 'clone' of undefinedrun @ Owl.carousel.min.js:1e @jquery.js:548e.update @Owl.carousel.min.js:1(Anonymous Function) @Owl.carousel.min.js:1e jquery.js:548
– Jefferson Mello Olynyki
Now it is working but it is not sending the id of the record in onclick Function like(id,identify){ $. ajax({ url:("ajax/like.php"), type: "POST", date: "udid="+id, Success:Function(data){ $("#"+identify). html(data); }})} echo "<button id='$guidcurti' role='button' onClick='curti($guid,$guidcurti)' class='btn btn-default fa fa-Thumbs-o-up'>($like)</button>";
– Jefferson Mello Olynyki