blockUI 错误“对象不支持此属性或方法”

发布于 2024-10-20 21:53:48 字数 653 浏览 6 评论 0原文

我在 VS2010 中运行它,提交表单时出现错误,显示“Microsoft JScript 运行时错误:对象不支持此属性或方法”。有什么建议吗?

<script type="text/javascript">
function BlockUI() {
    $.blockUI({ message: "<h1>Remote call in progress...</h1>" });
}
</script>

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnSuccess = "",
        OnBegin = "BlockUI()",
        OnComplete = "",
        OnFailure = "alert('Failed to update switch')",
        Confirm = "",
        HttpMethod = "POST",
        LoadingElementId = "",
        Url = ""
    }))

I'm running this from within VS2010 and an error comes up when the form is submitted which says "Microsoft JScript runtime error: Object doesn't support this property or method". Any suggestions?

<script type="text/javascript">
function BlockUI() {
    $.blockUI({ message: "<h1>Remote call in progress...</h1>" });
}
</script>

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnSuccess = "",
        OnBegin = "BlockUI()",
        OnComplete = "",
        OnFailure = "alert('Failed to update switch')",
        Confirm = "",
        HttpMethod = "POST",
        LoadingElementId = "",
        Url = ""
    }))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等风也等你 2024-10-27 21:53:48

您应该更改

OnBegin = "BlockUI()",

OnBegin = "BlockUI"

根据 MSDN OnBegin 需要:

JavaScript 函数的名称
在页面更新之前调用。

附加的 () 可能会使底层 JavaScript 立即执行该函数,从而导致错误。

类似地,对于 OnFailure

OnFailure = "function() { alert('Failed to update switch'); }",

此外,您不需要指定未使用的 AjaxOptions 的属性值:

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnBegin = "BlockUI",
        OnFailure = "function() { alert('Failed to update switch'); }",
        HttpMethod = "POST"
    }))

You should change

OnBegin = "BlockUI()",

to

OnBegin = "BlockUI"

According to MSDN OnBegin takes:

The name of the JavaScript function to
call before the page is updated.

The additional () probably makes the underlying JavaScript execute the function immediately, causing the error.

Similarly, with OnFailure:

OnFailure = "function() { alert('Failed to update switch'); }",

Also, you don't need to specify property values of AjaxOptions that you aren't using:

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnBegin = "BlockUI",
        OnFailure = "function() { alert('Failed to update switch'); }",
        HttpMethod = "POST"
    }))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文