的onSuccess如何衡量一个ASP.NET MVC ActionLink的? [英] How is OnSuccess measured for a ASP.NET MVC ActionLink?

查看:257
本文介绍了的onSuccess如何衡量一个ASP.NET MVC ActionLink的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白究竟ASP.NETs ActionLinks如何工作。我看到他们拥有的onSuccess和onFailure处一个事件处理程序,但我无法找到任何介绍如何成功和失败是确定的。

I don't exactly understand how ASP.NETs ActionLinks work. I see that they have a event handler for OnSuccess and OnFailure, but I can't find anything that describes how success and failure is determined.

我要建一个ASP.NET MVC应用程序并在其中我有一个Ajax.ActionLink,允许使用AJAX ...类同Digg的项目我投票。该ActionLink的序幕我的控制器和控制方法......一切工作正常这里。

I'm building an ASP.NET MVC application and within it I have a Ajax.ActionLink that allows me to "vote" on items using AJAX...similiar to Digg. The Actionlink kicks off my Controller and method...everything is working fine here.

在我的控制器我有检查,看看是否该用户已经过投票逻辑。我想用的onSuccess和onFailure处,以不同的反应。我希望它运行我的JavaScript函数PlusOneVote如果用户从未投票(这是的onSuccess情况下),如果用户已经投票之前,我想我的运行javascript函数CheaterYouCantVoteTwice。

In my controller I have logic that checks to see if this user has voted before. I wanted to use "OnSuccess" and "OnFailure" to respond differently. I want it to run my Javascript function "PlusOneVote" if the user has never voted (This is the OnSuccess scenario) and if the user has voted before I want run my javascript function "CheaterYouCantVoteTwice".

有人能解释onFailure处和的onSuccess如何衡量?

Can someone explain how OnFailure and OnSuccess are measured?

有人可以解释我怎么能建立这样的逻辑......在那里我可以在一个分支运行一个JavaScript函数(在我的情况下,如果用户从未投票),并在案件另一个JavaScript函数,用户已经投票?

Can someone explains how I can build this logic...where I can run one Javascript function in one branch (in my case, if the user has never voted) and another Javascript function in the case that the user has already voted?

推荐答案

成功是基于Ajax响应的HTTP状态code,仅此而已测量。基本上,如果你得到一个400级code(所有的400 - 417),你会得到一个失败。如果你得到一个200,它被认为是成功的。

Success is measured based on the HTTP Status code of the ajax response, and nothing more. Basically if you get a 400 level code (any of 400 - 417), you'll get a failure. If you get a 200, it's considered a success.

我认为你需要检查数据的内容在你的onSuccess处理决定做什么,而不是考虑一种类型的失败消息和一个类型成功消息。从阿贾克斯的角度来看,它是成功的,如果返回有效响应。

I think you'll need to examine the contents of the data in your OnSuccess handler to determine what to do, rather than considering one type a failure message and one type a success message. From the ajax perspective, it was successful if a valid response was returned.

这篇关于的onSuccess如何衡量一个ASP.NET MVC ActionLink的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆