目标是在回发时启动jQuery AJAX POST的相同控件
Target the same control that initiated a jQuery AJAX POST on postback
function pageLoad() {
$(".VoteUp").live("click", function () {
var Id = $(this).attr("index");
d = JSON.stringify({ "Id": Id })
$.ajax({
type: 'POST',
url: '../API/Services.asmx/LikeId',
data: d,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: testFunc,
error: errFunc
});
$(".VoteUp").each(function () {
$(this).attr("disabled", "disabled");
});
});
function testFunc(result, userContext, methodName) {
if (result.d[0] == "true") {
TheVoteUpControl.val("added");
}
else {
TheVoteUpControl.val("deleted");
}
$(".VoteUp").each(function () {
$(this).removeAttr("disabled");
});
}
function errFunc() {
alert('error');
}
如何在成功时更改相同的.VoteUp控件的值?我似乎不知道该如何瞄准发起事件的控制组。$ (" .VoteUp ")
建议吗?
我能想到的唯一方法是在全局变量中缓存元素,并在成功回调中捕获它。我还分别在complete
和beforeSend
回调中移动了$(".VoteUp")
的启用和禁用
$(".VoteUp").live("click", function (e) {
e.preventDefault();
$this=$(this); <-- cache this in the global variable
var Id = $(this).attr("index");
d = JSON.stringify({ "Id": Id })
$.ajax({
beforeSend:function(){
$(".VoteUp").attr("disabled", "disabled");
},
type: 'POST',
url: '../API/Services.asmx/LikeId',
data: d,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: testFunc,
error: errFunc
complete:function(){
$(".VoteUp").removeAttr("disabled");
}
});
});
function testFunc(result, userContext, methodName) {
if (result.d[0] == "true") {
$this.val("added");
}
else {
$this.val("deleted");
}
}
相关文章:
- 如何在php文件中获取$.post-ajax传递的值
- j查询如何在加载了 load() 函数的页面上进行 POST/AJAX,而无需刷新页面
- 使用Jquery和PHP在POST Ajax之后返回(一个空字符串)
- 跳过Get/Post Ajax的FormsAuthenticationTicket过期
- 通过POST ajax调用下载文件
- jQuery POST Ajax request
- 如何使用Symfony和Jquery发出POST Ajax请求
- 如何从 获取返回对象的类型.POST ajax 调用
- 在 POST ajax 处理程序中更改 window.location 会发出新的 ajax 调用,而不是重定向
- 如何从POST ajax响应中获取特定值
- return request method = GET but i send request = POST (ajax)
- 不使用代理的跨域POST Ajax请求
- 如何POST ajax并获得响应
- "错误“;或“;失败”;在jQuery中调用$.post Ajax
- POST, AJAX, and PHP : JSON submission
- 在$.post() ajax JQuery中添加认证头
- (将.从POST ajax请求Symfony2获取数据错误
- jquery -通过POST (ajax)发送JSON数据并在php中检索
- 如何在通过POST AJAX请求提交时向表单添加数据
- Post Ajax函数返回真或假