开发者

blockUI error "Object doesn't support this property or method"

开发者 https://www.devze.com 2023-02-15 05:06 出处:网络
I\'m running this from within VS2010 and an error comes up when the form is submitted which says \"Microsoft JScrip开发者_如何学运维t runtime error: Object doesn\'t support this property or method\".A

I'm running this from within VS2010 and an error comes up when the form is submitted which says "Microsoft JScrip开发者_如何学运维t 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 = ""
    }))


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"
    }))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号