开发者

Append result with ajax calling a php file

开发者 https://www.devze.com 2023-02-16 14:58 出处:网络
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.

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

精彩评论

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

关注公众号