简体   繁体   English

Ajax ActionLink OnSuccess调用带参数的javascript函数,错误:必需对象

[英]Ajax ActionLink OnSuccess call javascript function with parameters, Error: Object required

Using Ajax.ActionLink's OnSuccess-Event brings me some trouble. 使用Ajax.ActionLink的OnSuccess-Event给我带来了一些麻烦。

As asked here the function cannot be called directly. 如此处要求的那样该函数不能直接调用。 I tried all the suggestions I found, I get a message "Object required". 我尝试了所有发现的建议,并收到消息“需要对象”。 The javascript-function expects an event, which is nothing/null when I pass it the correct way. javascript函数需要一个事件,当我以正确的方式传递该事件时,该事件为空。

Code snippets 代码段

Before: 之前:

 OnSuccess = "ListApi.ResetAddLink(window.event, '" + AdressListIndexName + "')",

After: 后:

OnSuccess = "function(){ListApi.ResetAddLink(window.event," + AdressListIndexName + ");}",

The Function ResetAddLink: 函数ResetAddLink:

ListApi.ResetAddLink = function(_evt, ListIndexName) {
evt = _evt || window.event;
var target = evt.target || evt.srcElement;

var Index = parseInt(document.getElementById(ListIndexName).value);
var Pre = target.href.substring(0, target.href.lastIndexOf("=") + 1);

Index = Index + 1;
document.getElementById(ListIndexName).value = Index;

target.href = Pre + Index;
}

Questions 问题

  1. Is the new OnSuccess call correct? 新的OnSuccess呼叫正确吗?
  2. How do I pass the event to the function? 如何将事件传递给函数? Or how can I get the event? 或如何获得活动?

I'm pretty new to Ajax and Javascript in general, maybe I miss just a little piece :( 总的来说,我对Ajax和Javascript还是很陌生,也许我只想念一小段:(

Thanks for any help 谢谢你的帮助

Regards 问候

PS: I know there are some troubles about adress and address, but I copy/pasted as it is for now. PS:我知道地址和地址有一些麻烦,但是我现在照原样复制/粘贴。 I also noticed that the error only occurs in internet explorer, firefox seems to get the event. 我还注意到,该错误仅发生在Internet Explorer中,Firefox似乎触发了该事件。

试图通过事件,但是没有用...所以我更改了参数,现在我从外部传递了事件所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Ajax.Actionlink OnSuccess上的Model id传递给另一个Javascript函数 - Passing Model id on Ajax.Actionlink OnSuccess to another Javascript function 如何使用prototypejs ajax onSuccess事件调用现有的已定义JavaScript函数? - How to call an existing defined javascript function with an prototypejs ajax onSuccess event? Onclick一个Ajax.ActionLink我需要调用一个Javascript函数 - Onclick of a Ajax.ActionLink I need to call a Javascript function 使用TempData完成时,MVC3 Ajax ActionLink可以调用javascript函数 - MVC3 Ajax ActionLink to call javascript function when completed with TempData 使用ajax从相同的javascript函数进行多次调用,函数主体与ajax成功回调之间参数中的对象不同 - Multiple call from same javascript function with ajax, object in parameters not the same between the function body and the ajax success callback 如何使用参数从javascript调用ajax函数 - how to call ajax function from javascript with parameters 在Ajax.ActionLink的中间运行javascript函数 - Run javascript function IN the middle of Ajax.ActionLink 在C#ActionLink中调用JavaScript函数 - Call javascript function in c# actionlink 如何通过actionLink调用javascript函数 - How to call javascript function through actionLink 如何在actionlink mvc 4中调用javascript函数? - how to call a javascript function in actionlink mvc 4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM