AJAX调用没有击中控制器,但仍然成功的功能 [英] AJAX Call not hitting controller but still goes to success function

查看:74
本文介绍了AJAX调用没有击中控制器,但仍然成功的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的js文件中有一个ajax调用,它调用一个返回局部视图的动作方法。



这个ajax调用第一次触发控制器上的断点它被称为。但是下一次它没有达到断点但它仍然转到ajax调用的成功函数,成功调用的结果是页面的完整html,其中还包括继承的布局。



有谁能告诉我这里发生了什么以及可能的解决办法吗?

js代码看起来像这样。



var UrlRoot.History ='@ Url.Action(Action,MyController,new {Area =ControllerArea})';

$ .ajax({

url:UrlRoot.History,

类型:'POST',

数据类型:'json',

数据:params,// params被传递(在第一次调用时正确传递)

成功:函数(结果){

调试器;

if(result!= null){

if(result ==请从匹配中选择任何行制造商加载数据!!!){

$(#NoRecord)。show();

$(#NoRecord)。html('' );

$(#NoRecord)。html(结果);

}

else {

$(#tab_1)。html('');

$(#tab_1)。html(result); //使用操作方法返回的部分视图填充标签内容。

}

}

},

I have an ajax call in my js file which calls an action method returning a partial view.

This ajax call hits the breakpoint on controller for the first time it is being called. But the next time it is not hitting the breakpoint but it still goes to the success function of ajax call and the result of the success call is the complete html of the page which also includes the layout being inherited.

Could anyone please tell me what is happening here and the possible solution to this?
The js code looks like this.

var UrlRoot.History = '@Url.Action("Action", "MyController", new { Area = "ControllerArea" })';
$.ajax({
url: UrlRoot.History,
type: 'POST',
datatype: 'json',
data: params, // params being passed(which is passed correctly at the first call)
success: function (result) {
debugger;
if (result != null) {
if (result == "Please select any row from match maker to load data!!!") {
$("#NoRecord").show();
$("#NoRecord").html('');
$("#NoRecord").html(result);
}
else {
$("#tab_1").html('');
$("#tab_1").html(result); // Fill the tab content with partial view returned from action method.
}
}
},

推荐答案

.ajax({

url:UrlRoot.History,

类型:'POST',

数据类型:'json',

数据:params,//传递参数(在第一次调用时正确传递)

成功:函数(结果){

调试器;

如果(结果!= null){

if(result ==请从匹配器中选择任何一行来加载数据! ){
.ajax({
url: UrlRoot.History,
type: 'POST',
datatype: 'json',
data: params, // params being passed(which is passed correctly at the first call)
success: function (result) {
debugger;
if (result != null) {
if (result == "Please select any row from match maker to load data!!!") {


(#NoRecord)。show();
("#NoRecord").show();


(#NoRecord) .html('');
("#NoRecord").html('');


这篇关于AJAX调用没有击中控制器,但仍然成功的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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