Skip to content Skip to sidebar Skip to footer

Function Only Defined But Immediately Executed Anyway

I'm having trouble with a short javascript code in my file ajaxrequest.js . Here it is : function afficher () { $.post('requete_affichage.php', function (data) { $('#name-dat

Solution 1:

By including the brackets after the function you are telling it to execute immediately. To assign the function reference to the click handler, remove the brackets:

$('#bouton2').on('click', afficher);

Post a Comment for "Function Only Defined But Immediately Executed Anyway"