开发者

Jquery ajax responses with load();

I am working on a comment voting system.

I have a page profile_new.php?id=194

That page then uses jquery tabs to load an external file of sketch-comments.php?id=194&thumb=images/thumbs/1.png

Then in that tab the comments are in a scrolling div (jqueryScrollPane- http://jscrollpane.kelvinluck.com/)

Then, on each comment, it uses a rollover to show the + and - button. (Just like youtube)

Here is the div that shows up on rollover. (just showing one button)

<div class="comRate" id="c<?php echo $comID;?>">
    <div id="up<?php echo $comID;?>" >
        <a href="#" id="addUpDown" rel="blah"> show number of "+" here </a>
    </div><!--up-->
</div><!--comRate-->

My question: Does all this extra stuff matter when I just want to reload this div on the ajax response in order to display an updated number? I'm having trouble understanding how to use the load(); function to say the least.

How can I just reload the .comRate div? Do I ne开发者_如何学Ced all the variables I used to rebuild the URLS to get to this spot?

    $("#c" + comID).load(????????);

Thanks! Dave


I am guessing you need to send the comId back to the server to get the correct number of responses?

If so you would could use it like this?

$("#up" + comID").next().load("YourUpdateUrl.php?id=" + comID);

load() takes the value from passed resource location and loads the value into the component. jQuery doc: http://api.jquery.com/load/

So if YourUpdateUrl.php returned echo "<strong>15</strong>";

<div id="test"><div>
$("#element").load("YourUpdateUrl.php"); = <div id="test"><strong>15</strong></div>


From a usability stand point, I recommend that you just submit the vote via ajax and iterate the number + 1.

For example, if the comment has 1 vote, and I add a vote, it will always show 2 rather than whatever number it might actually be because other people have voted that I don't know about.

This prevents confusion of clicking a +1 vote and then it updates to +123. The user has no idea what just happened.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜