Skip to content

Instantly share code, notes, and snippets.

@demofan
Created August 19, 2017 10:00
Show Gist options
  • Save demofan/a12e2b2ba7442cbc774f33bd7d8a5619 to your computer and use it in GitHub Desktop.
Save demofan/a12e2b2ba7442cbc774f33bd7d8a5619 to your computer and use it in GitHub Desktop.
Unobtrusive sample
@Html.Hidden("ajaxUrl",Url.Action(""))
<button type="button" data-ajax-url="@Url.Action("")"></button>
<script>
$(function () {
$(":input[data-ajax-url]").click(function (e) {
e.preventDefault();
var current = $(this);
$.ajax({
type: "POST",
url: current.data("url"),
data: "name=John&location=Boston",
dataType: "json",
success: function (response) {
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment