【问题标题】:Uncaught TypeError: Illegal invocation未捕获的类型错误:非法调用
【发布时间】:2014-01-10 16:11:19
【问题描述】:

我在 Google 上搜索过,并且还浏览了 Stack 上提供的类似问题列表,但不幸的是,没有人能帮助我解决问题。

下面是我正在做的事情,我从我的主视图中调用了 PartialView,但我的 PartialView 没有被调用。

下面是我的代码。

     $("#Status").live("change", function () {
         $.getJSON("/../My_Controller/My_Partial_View", { Parameter1: $("#Parameter1").attr("value")}, function (data) {
           My logic         
         });
     });

但以下代码不起作用,我收到以下错误。 尽管此代码在我的其他解决方案中运行良好,并且我的 PartialViews 确实被调用了。

这是我遇到的错误。

更新

如果我以这种方式传递参数,那么我的代码正在访问局部视图。

 $.get("/../My_Controller/My_Partial_View?Param1=1", function (data) {
      $("#TableEmployee tbody").append(data);
 });

【问题讨论】:

  • @Matheletics,那么我应该使用哪个替代方案?我希望在某个文本框离开时获取 partialView
  • api.jquery.com/on -- 新的live
  • @elclanrs 是的,这就是我尝试过的,$("#My_Control").on("change",我添加了一个警报代码来测试,它给了我一个警报,但又是它显示同样的错误,Uncaught TypeError: Illegal invocation and not into the PartialView in controller
  • on有多种使用方式,请寻找“事件委托”。
  • “on”事件处理程序工作正常,因为值更改或单击和其他事件时会弹出警报,但未调用局部视图。

标签: javascript jquery asp.net-mvc-3


【解决方案1】:

我想你忘了指定请求类型和返回类型

这里是示例:

 $.ajax({ 
            url: "yoururl", 
            data: "parameter1=1", 
            success: successevent, 
            type: 'GET', 
            dataType: 'json' 
        });

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2019-04-29
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2011-05-15
    • 1970-01-01
    相关资源
    最近更新 更多