且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过单击链接发送 AJAX 请求而不重定向用户

更新时间:2023-09-28 23:02:10

你必须做类似的事情

$('.classofyourlink').click(function(e){
  e.preventDefault();//in this way you have no redirect
  $.post(...);//Make the ajax call
});

通过这种方式,用户通过点击链接而不重定向来进行ajax调用.以下是 $.post

in this way the user makes an ajax call by clicking a link without redirecting. Here are the docs for $.post

编辑 - 在你的情况下将值传递给 jQuery,你应该做类似的事情

EDIT - to pass the value to jQuery in your case you should do something like

$('.order_this').click(function(e){
  e.preventDefault();//in this way you have no redirect
  var valueToPass = $(this).text();
  var url = "url/to/post/";
  $.post(url, { data: valueToPass }, function(data){...} );//Make the ajax call
});