开发者

Can someone explain this javascript function?

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} ('+h开发者_如何学Gotml+')').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.


  1. A function VOTEYES is defined that takes 2 arguments id and nb
  2. It finds an element with an ID of 'vote'+id, so if id was 2 it would be vote2
  3. It hides that element making it non-clickable.
  4. It does an ajax request, POST call to whatever $baseurl, the root domain I suppose, is and appends vote_yes.php to it
  5. It passes the id and nb parameters in the POST request.
  6. Then it takes the html from that vote_yes.php page and appends it to the vote2 element by fading it in.


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.


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.


I believe the first line inside the function hides the button so the user can't click it again.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜