Skip to content

Instantly share code, notes, and snippets.

@squidge
Created November 8, 2011 16:16
Show Gist options
  • Save squidge/1348218 to your computer and use it in GitHub Desktop.
Save squidge/1348218 to your computer and use it in GitHub Desktop.
How to use AjaxContinuation in FubuMVC
<script>
$(document).ready(function() {
$("#btnSubmit").click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
dataType: "json",
url: "log-on",
data: $("#logonForm").serialize(),
success: function (response) {
/* when server-side validation fails AjaxContinuation output reads:
{ "success":false,
"errors":[{
"category":null,
"field":"UserName",
"message":"Required Field"
},
{
"category":null,
"field":"Password",
"message":"Required Field"
}
]
}
*/
if(response.success == false){
for (var i=0; i<response.errors.length; i++)
$("#"+response.errors[i].field).addClass("error");
}
},
error:function(x,e){
alert("error : " + x.status + " - " + e);
}
});
});
});
</script>
<form id="logonForm" action="log-on" method="post">
<label>Username</label>
<input type="text" id="UserName" name="UserName" />
<label>Password</label>
<input type="password" id="Password" name="Password" />
<input id="btnSubmit" type="submit" value="go"/>
</form>
public class PostHandler
{
public FubuMVC.Core.Ajax.AjaxContinuation Execute(LogOnInputModel input)
{
return new FubuMVC.Core.Ajax.AjaxContinuation
{
Success = true
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment