English 中文(简体)
Jquery从php到<li>在本例中取得结果
原标题:Jquery, get results from php to <li> in this example

因此,这是充分的表决制度,但现在需要从实验室获得结果,并将结果投入到目前的班级,以取代以下的{SCORE}。 需要一些帮助,我总是感激。

午餐:

<ul class="star-rating" id="{$ID}">
<li class="current-rating" style="width:{$SCORE}%;"></li>
<li><a href="#" class="one-star"></a></li>
<li><a href="#" class="two-stars"></a></li>
<li><a href="#" class="three-stars"></a></li>
<li><a href="#" class="four-stars"></a></li>
<li><a href="#" class="five-stars"></a></li>
</ul>

<div style="display:none;" id="msgOK-{$ID}">Vote</div>
<div style="display:none;" id="msgWRONG-{$ID}">Wrong</div>
<div style="display:none;" id="msgLOGIN-{$ID}">Login</div>

Jquery:

   $(function() {

    $( ul.star-rating ).on( click ,  a , function() { // jquery 1.7+

      var score = this.className,
      id = $(this).closest( ul )[0].id;

      $.ajax({ 
            type: "POST",
            url: "js/ajax.php",
            data: {id: id, score: score},
            success: function(pass) {
                if(pass ==  1 ) {
                          // all ok
                     $("div#msgOK-" + id).delay(200).fadeIn(2000).delay(3000).fadeOut(2000);
                     $("ul.star-rating#" + id).hide(100).delay(7100).show( fast );
                } else if(pass ==  2 ) { 
                          // something went wrong
                     $("div#msgWRONG-" + id).delay(200).fadeIn(2000).delay(3000).fadeOut(2000);
                     $("ul.star-rating").hide(100).delay(7100).show( slow );
                } else if(pass ==  3 ) {
                             // you need to be logged in to vote
                     $("div#msgLOGIN-" + id).delay(200).fadeIn(2000).delay(3000).fadeOut(2000);
                     $("ul.star-rating").hide(100).delay(7100).show( slow );
                }
             }
          });
         return false;
       });
    });
问题回答

为什么在一米宽的笼子里有用户分,但在这里,你将如何把新的评级带入 w财产。 在你的成功职能中,添加以下内容:

  success: function(pass) {
            //you need to make  pass  an object on your php side with fields
            //more on that below
            if(pass.errorlvl ==  1 ) {
              $(".current-rating").css( width , pass.userscore );
              $("div#msgOK-" + id).delay(200).fadeIn(2000).delay(3000).fadeOut(2000);
              $("ul.star-rating#" + id).hide(100).delay(7100).show( fast );
            }
            ....

您的实验室应当成为这样的物体(或联系阵列):

 $myerror_lvl = 1
 $new_score = "3.5"
 return array("errorlvl": $myerror_lvl, "userscore": $new_score);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签