[英]How to execute other function after @Url.Action with javascript
In my mvc application i use the @url.action to get new data and show it in the page. 在我的mvc应用程序中,我使用@ url.action获取新数据并将其显示在页面中。 The problem that i have right now is that i want to excute more javascript after the @url.action
我现在遇到的问题是,我想在@ url.action之后使用更多的javascript
function find(elm)
{
var keyWord = $('input', $(elm).parent()).val();
$('#searchResults').load('@Url.Action("Search", "Search")', {
searchText: keyWord });
// I want to load here a other function aswell
}
How can i achieve this? 我怎样才能做到这一点?
You can execute your other functions inside the complelte call back of jQuery load
method 您可以在jQuery
load
方法的完整回调内执行其他功能
var keyWord ="dummy";
var url='@Url.Action("Search", "Search")';
$('#searchResults').load(url, {searchText: keyWord },function(){
alert("Load complete.Do somethign else now");
});
The callback function will be executed when the xhr request completes. xhr请求完成后,将执行回调函数。
You can also use $.post
where you can do your custom stuff inside the done
event. 您还可以使用
$.post
在done
事件中执行自定义done
。 You can also wire up a fail
event as well to catch errors. 您还可以连接
fail
事件以捕获错误。
var keyWord ="dummy";
var url='@Url.Action("Search", "Search")';
$.post(url, {searchText: keyWord }).done(function(r) {
$('#searchResults').html(r);
alert("ajax call done.Do somethign else now");
}).fail(function(x, a, e) {
console.log(x);
console.log(a);
alert(e);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.