Reputation: 717
I have this javascript function I am trying to understand. I don't know if it has been implemented in jquery.
It is a function that is related to a button. When the button is clicked on it should display on the screen that vote has been cast. Can you explain to me the purpose of 'id' and 'nb' in this function and what each line does. I presume the fourth line takes the user to vote_yes.php of the base url if they click on the button? $lang189 is a variable saying vote collected and output between the literal braces is html and javacript, with code outside the braces php.
{literal}
function VOTEYES(id,nb) {
$('#vote'+id).css('display','none');
$.post("{/literal}{$baseurl}/vote_yes.php{literal}",{"id":id,"nb":nb},function(html) {
$('#vote'+id).html('{/literal}{$lang189}{literal} ('+html+')').fadeIn();
});
}{/literal}
I am familar with PHP not no javascript experience.. I don't want to learn the whole language to understand how this vote button works, please help. Cookies are involved.
Thanks.
Upvotes: 0
Views: 233
Reputation: 386
Will send id and nb to vote_yes.php. response output will be on (html) variable. now with $('#vote'+id).html(xxx) will set that the response received will be content of another html element.
Upvotes: 0
Reputation: 32851
I believe the first line inside the function hides the button so the user can't click it again.
Upvotes: 0
Reputation: 4315
Yes, it is using jQuery. It appears that the id is being used to determine which element with the id of voteID to use. I'm not quite sure what the nb is used for because it is simply passed as a POST variable to the vote_yes.php page in the AJAX. I would investigate that page for more info.
Upvotes: 0
Reputation: 186742
VOTEYES
is defined that takes 2 arguments id
and nb
id
was 2 it would be vote2
$baseurl
, the root domain I suppose, is and appends vote_yes.php
to itid
and nb
parameters in the POST request.vote_yes.php
page and appends it to the vote2
element by fading it in.Upvotes: 2
Reputation: 245489
The function is simply making a call to a page with the URL:
{/literal}{$baseurl}/vote_yes.php{literal}
And passing in the following parameters via "POST":
"id": id
"nb": nb
and using jQuery to fade in the response from the page.
Upvotes: 0