开发者

Append result with ajax calling a php file

I am using jQuery and ajax function to access a php file that echo yes or no depending o开发者_如何学Cn the value that is send thru POST. It checks the status of different urls. The problem is I cannot append that result to the specific line (or even better to replace "status" with the response). I have a table like this:

<table>
<tr><td>URL1</td><td><a href="url1" class="status">status</a><span class="result"></span></td></tr>
<tr><td>URL2</td><td><a href="url2" class="status">status</a><span class="result"></span></td></tr>
<tr><td>URL3</td><td><a href="url3" class="status">status</a><span class="result"></span></td></tr>
</table>

And the jquery code is:

(function($) {
    $(document).ready(function() {
        $('.status').click(function(event) {
        var href = $(this).attr('href');
        $.ajax({
            url: 'status.php',
            type: 'POST',
            data: 'href=' + href,
            succes: function(result) {              
                $('.result').append(result);
            }
        });
        return false;
        });
    });

})(jQuery);

I get the response but I cannot append it (or even better to replace "status" text with the response). Thank you.


Try like this:

(function($) {
    $(function() {
        $('a.status').click(function() {
            $(this).next('span.result').load('status.php', { href: this.href });
            return false;
        });
    });
})(jQuery);

And a live demo.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜