Onclick事件,用于发送ajax请求的链接

时间:2013-06-12 15:19:20

标签: javascript html ajax

如果您在页面上有一个单词要捕获onclick事件并从中发送ajax请求,那么该怎么做?

1 个答案:

答案 0 :(得分:2)

jQuery让这很容易!

HTML

<div>Here's the <span class="myLink">word</span></div>

的JavaScript

$(document).ready(function() {
    /*onclick event*/
    $(".myLink").click(function() {
        /* The AJAX call*/
        $.post('http://myurl.com/',{ 'my' : 'data'},function(response) {
            //do something with the result
        });
    });
});