jQuery: Capture anchor href onclick and submit asynchronously

后端 未结 3 398
清歌不尽
清歌不尽 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:41

    Try this

    $('a').click(function (event) 
    { 
       event.preventDefault(); 
    
       var url = $(this).attr('href');
       $.get(url, function(data) {
         alert(data);
        });
    
     });
    

提交回复
热议问题