I've got an Ajax.ActionLink like so:
@Ajax.ActionLink("Load Related Titles",
"AjaxLoadRelated",
"Shared",
new { RelatedComics = c.RelatedComic.RelatedTitles },
new AjaxOptions() { HttpMethod = "Get", UpdateTargetId = "divRelatedTitles", LoadingElementId = "divLoading", OnBegin = "ajaxLoadMoreBegin", OnFailure = "ajaxLoadMoreFailed", OnSuccess = "ajaxLoadMoreSuccess" })
Currently my OnSuccess function looks like so:
function ajaxLoadMoreSuccess() {
...
}
I would like to pass an argument to it:
function ajaxLoadMoreSuccess(myArg) {
...
}
Is this possible?
Thanks in advance
It's possible to do. The mvc ajax unobtrusive script creates an anonymous function with three parameters(corresponding to the parameters for the jquery ajax complete method) data, status, xhr and calling that method with the arguments for the jquery ajax complete method. So for example:
...OnSuccess = "ajaxLoadMoreSuccess1('hello world')"
Or
...OnSuccess = "ajaxLoadMoreSuccess2(calc(), data, status, xhr)"
<script type="text/javascript">
function ajaxLoadMoreSuccess1(message) {
alert(message);
}
function ajaxLoadMoreSuccess2(x, data, status, xhr) {
$('#somespan').text('calc was ' + x + ' and data is ' + data);
}
function calc() {
return 1 + 2;
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With