jQuery: Capture anchor href onclick and submit asynchronously

后端 未结 3 399
清歌不尽
清歌不尽 2020-12-23 21:09

I almost never get to play with client-side stuff, and this presumably simple task is kicking my butt :)

I have some links. OnClick I want to prevent the default act

3条回答
  •  鱼传尺愫
    2020-12-23 21:24

    $('a').click(function(event) { 
        event.preventDefault(); 
        $.ajax({
            url: $(this).attr('href'),
            success: function(response) {
                alert(response);
            }
        });
        return false; // for good measure
    });
    

提交回复
热议问题