随机重定向到/未定义 [英] Random redirect to /Undefined
问题描述
我工作的一个内部MVC的网站。
I'm working on an internal MVC site.
问题:
突然,该网站已经开始重定向到本地主机/未定义
在选择浏览器(Chrome浏览器,Opera和Safari)前/删除POST之后。这不会发生在Firefox或IE浏览器。
Suddenly the site has started redirecting to localhost/undefined
in select browsers (Chrome, Opera, and Safari) before/after a delete POST. This does not happen in Firefox or IE.
采取的步骤:
我已经通过下面的JavaScript code无数次在Chrome上台阶(没有工作)和IE(工作)。似乎有没有什么区别比铬整理与随机重定向后,在code,它不叫其他的。
I've stepped through the following javascript code numerous times on Chrome(not working) and IE(working). There appear to be no difference other than Chrome finishing with a random redirect that is not called upon in the code.
jQuery的AJAX调用如下:
// Delete button clicked
function deleteEntity(e) {
e.preventDefault();
var name = $(this).attr("name");
var index = $(".deleteEntity[name=" + name + "]").index($(this));
var entityId = ko.utils.unwrapObservable(viewModel.model.peek()[index].ID);
var data = { EntityID: entityId };
viewModel.model.remove(viewModel.model.peek()[index]);
if (entityId > 0) {
$.ajax({
url: "/" + name + "/Delete",
type: "POST",
data: data,
dataType: 'json',
async: true,
success: function (data, textStatus, xhr) {
alert(data);
},
error: function (xhr, textStatus, errorThrown) {
// Decide later.
}
});
}
}
$(document).on("click", ".deleteEntity", deleteEntity);
调试步骤
在开始在Ajax调用的线路断路。 - > 如果(entityId> 0){
Starting at a break at the line of the ajax call. -> if (entityId > 0) {
.
- 如果我按F8在这里通过我的休息时间在
成功
和错误
的功能,它结束了不打任何断点,并重定向到本地主机/未定义
没有联系服务器。 - 如果我打F10单步调试它会停在我的断点删除操作在服务器上。从那里,我在Visual Studio中按F5键,它删除选定的预期实体返回我对我在broswer断点。如果我从这里按F8也将达到成功,弹出成功的提示框。
- 如果我在broswer按F8按F5在Visual Studio之前,但它会立即重定向到
本地主机/未定义
。
- If I hit F8 here to pass through to my breaks at the
success
anderror
functions, it ends up not hitting either of the breakpoints and redirecting tolocalhost/undefined
without contacting the server. - If I hit F10 to step through it will stop at my breakpoint on the server in the delete action. From there I hit F5 in visual studio and it deletes the selected expected entity returning me to my breakpoint in the broswer. If I hit F8 from here it will hit success and popup the alert box with success.
- If I hit F8 in the broswer before hitting F5 in visual studio however it will instantly redirect to
localhost/undefined
.
问:有谁知道这个问题的由来?我GOOGLE了四周,发现有关的插件,所以我尝试禁用所有的(全2)非常类似的问题,并没有改变任何东西。
Question: Does anyone know the origin of this problem? I've googled around and found a very similar issue relating to plugins so I tried disabling all of the (a whole 2) and it did not change anything.
P.S。如果任何其他code段将有助于只是评论,我会添加它们。我已经在至少20次检查了我的行动。该删除
是 [HttpPost]
但这样是我的更新
和它的正常工作,在完全相同的方式。
p.s. if any other code snippets will be helpful just comment and I'll add them. I've checked my actions over at least 20 times. The Delete
is an [HttpPost]
but so is my Update
and it's working fine in the same exact fashion.
推荐答案
我通过从我的删除操作的 [HttpPost]
属性在我的控制器解决了这个问题。 (我不得不添加JSON的回报,使得到但那只是因为它不再是一个post请求)。
I solved the problem by removing the [HttpPost]
attribute from my Delete action in my controller. (I had to add the Json return to allow get but that was just because it was no longer a post request).
我的线索少,为什么它是导致这样的错误,并会要求一个独立的问题,在关于这一点。如果找到一个答案,我在这里将链接在这个岗位。
I am clue-less as to why it was causing such an error and will be asking a separate question in regards to that. If an answer is found I will link it here in this post.
这篇关于随机重定向到/未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!