Jquery 如何调用ajax方法
我有以下代码Jquery 如何调用ajax方法,jquery,ajax,Jquery,Ajax,我有以下代码 <li id="btemaildelete"><a href="##" onClick="return confirm('Are you sure you want to delete this Email Address?');"><i class="cus-cancel"></i> Delete</a></li> 你能帮我理解一下吗?这里有一个例子 $.ajax({ type: 'POST',
<li id="btemaildelete"><a href="##" onClick="return confirm('Are you sure you want to delete this Email Address?');"><i class="cus-cancel"></i> Delete</a></li>
你能帮我理解一下吗?这里有一个例子
$.ajax({
type: 'POST',
url: 'url',
data: '{ }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
// Do something interesting here.
}
});
如果包含jQuery:
$.get("emaildelete.cfm", {intuserid: 1}, function(data) {
// data contains the response of emaildelete.cfm
});
要捕获jQuery中的单击事件,可以执行以下操作:
HTML:
<a href="..." data-id="1">Delete</a>
JavaScript:
$(document).ready(function() {
$("a[data-id]").click(function() {
var confirm = confirm("Are you sure u wanna delete?");
if(!confirm) return false;
var deleteId = $(this).data("id");
$.get("emaildelete.cfm", {intuserid: deleteId}, function(data) {
// data contains the response of emaildelete.cfm
});
return false;
});
});
HTML:
JavaScript:
$(文档).ready(函数(){
$(“a[数据id]”)。单击(函数(){
var confirm=confirm(“您确定要删除吗?”);
如果(!confirm)返回false;
var deleteId=$(this.data(“id”);
$.get(“emaildelete.cfm”,{intuserid:deleteId},函数(数据){
//数据包含emaildelete.cfm的响应
});
返回false;
});
});
使用该代码,您不再需要“onclick”属性。尝试如下:
<li id="btemaildelete"><a href="##" onClick="call_function();"><i class="cus-cancel"></i> Delete</a></li>
您必须从链接本身传递id,不确定如何通过aspx填充这些链接。你只需要将电子邮件的id输入到链接的id中,但是你的应用程序可以做到这一点
<li class="btemaildelete"><a href="##" class="deleteLink" id="get your ID in here"
onClick="return confirm('Are you sure you want to delete this Email Address?');"><i
class="cus-cancel"></i> Delete</a></li>
$(".deleteLink").on("click",function(){
$.ajax({
type: 'POST',
url: 'emaildelete.cfm',
data: '{ intuserid : $(this).attr("id") }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
alert('Email deleted');
}
});
});
$(.deleteLink”)。在(“单击”,函数()上{
$.ajax({
键入:“POST”,
url:'emaildelete.cfm',
数据:{intuserid:$(this.attr(“id”)},
contentType:'application/json;charset=utf-8',
数据类型:“json”,
成功:功能(msg){
警报(“删除电子邮件”);
}
});
});
PageName.aspx/GetDate
?老实说,这并不是一个很好的答案。$.ajax({type:'POST',url:'emaildelete.cfm',data:'{intuserid:?????????}',contentType:'application/json;charset=utf-8',dataType:'json',success:function(msg){//在这里做点有趣的事情。});你尝试过什么…在这里发布一些代码…否则没有人能够帮助uColdfusion代码:现在如何调用ajax来启动带有参数的emailmarkactive.cfm。你能给链接一个id吗?
function call_function() {
if(confirm('Are you sure you want to delete this Email Address?'))
{
$.ajax({
url: "emaildelete.cfm?intuserid=1", //Or any other server page you want
type: "POST",
success: function (response) {
alert('Success' + response);
}
});
<li class="btemaildelete"><a href="##" class="deleteLink" id="get your ID in here"
onClick="return confirm('Are you sure you want to delete this Email Address?');"><i
class="cus-cancel"></i> Delete</a></li>
$(".deleteLink").on("click",function(){
$.ajax({
type: 'POST',
url: 'emaildelete.cfm',
data: '{ intuserid : $(this).attr("id") }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
alert('Email deleted');
}
});
});