• Compra una licencia de Windows 10/11 (10€) u Office (18€) al mejor precio u Office al mejor precio. Entra en este post con las ofertas
  • Conoce los Días Naranjas de PcComponentes: descuentos de hasta un 40% en tecnología. Entra en este post con las ofertas
  • ¡Bienvenid@! Recuerda que para comentar en el foro de El Chapuzas Informático necesitas registrar tu cuenta, tardarás menos de 2 minutos y te dará valiosa información además de ayudarte en lo que necesites o pasar un rato agradable con nosotros.

Contador de clicks

urbon

Nuevo
Registrado
30 Jun 2015
Mensajes
41
Puntos
0
Buenas! quisiera hacer una botón tipo facebook para saber cuántas personas votan , en el html tengo el botón , pero el script para contar para luego guardarlo en una bases de datos.Tengo una archivo .js pero no sé por dónde empezar, si me podrían ayudar estaría agredecido.

Este es el botón:

<input type="button" id="boton" value="Presiona Aqui" onclick="contador()" />

Y este es el archivo .js:

(function(){

$.appreciateButton = function(options){

// The options object must contain a URL and a Holder property
// These are the URL of the Appreciate php script, and the
// div in which the badge is inserted

if(!'url' in options || !'holder' in options){
return false;
}

var element = $(options.holder);

// Forming the url of the current page:

var currentURL = window.location.protocol+'//'+window.location.host+window.location.pathname;

// Issuing a GET request. A rand parameter is passed
// to prevent the request from being cached in IE

$.get(options.url,{url:currentURL,rand:Math.random()},function(response){

// Creating the appreciate button:

var button = $('<a>',{href:'',className:'appreciateBadge', html:'cojinudo'});

if(!response.voted){
// If the user has not voted previously,
// make the button active / clickable.
button.addClass('active');
}
else button.addClass('inactive');

button.click(function(){
if(button.hasClass('active')){

button.removeClass('active').addClass('inactive');

if(options.count){
// Incremented the total count
$(options.count).html(1 + parseInt(response.appreciated));
}

// Sending a GET request with a submit parameter.
// This will save the appreciation to the MySQL DB.

$.getJSON(options.url,{url:currentURL,submit:1});
}
{
alert ("Gracias!");
}


return false;
});

element.append(button);

if(options.count){
$(options.count).html(response.appreciated);
}
},'json');


return element;
}

})(jQuery);

Saludos.
 
Última edición:
Buenas

A ver, si quieres tener algo parecido al contador de likes en Facbook vas a necesitar crear una base de datos y un script con php que la modifique.

Para no tener que redirigirlos a otra página utilizas Ajax y listo.

De todas formas te recomendaría aprender php y sql si no sabes.
 
Arriba