Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将视图返回到ajax调用并替换html页面抛出';追加儿童';jquery中的异常_Javascript_Jquery_Asp.net Mvc - Fatal编程技术网

Javascript 将视图返回到ajax调用并替换html页面抛出';追加儿童';jquery中的异常

Javascript 将视图返回到ajax调用并替换html页面抛出';追加儿童';jquery中的异常,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我正在进行下面这样的ajax调用,返回这样的视图 return View("Finish"); 这将整个html页面作为字符串作为响应,因此我想用它替换页面,但当我这样做时,我收到一个错误 中第82行第3列的未处理异常 0x800a138f-JavaScript运行时错误:无法获取未定义或空引用的属性“appendChild” 有趣的是,它确实设置了html,所以我在屏幕上看到了正确的页面,我也看到了JQuery中的异常 var options = { url: scope.enumCon

我正在进行下面这样的ajax调用,返回这样的视图

return View("Finish");
这将整个html页面作为字符串作为响应,因此我想用它替换页面,但当我这样做时,我收到一个错误

中第82行第3列的未处理异常 0x800a138f-JavaScript运行时错误:无法获取未定义或空引用的属性“appendChild”

有趣的是,它确实设置了html,所以我在屏幕上看到了正确的页面,我也看到了JQuery中的异常

var options = {
  url: scope.enumControllers.saveEvent,
  type: "post",
  data: viewModel
};

$.ajax(options)
  .done(function(response) {
    if (response.error === true) {

      yb.base.eventAlert(response.message, "error");
    } else {

      $("html").html(response); // error here trying to set the page to the response html string

    }
  })
  .always(function() {

  })
  .fail(function(jqXHR, textStatus) {
    yb.base.eventAlert("Error saving data. Please contact the help desk.", "error");
  });

通过ajax替换整个页面不是一个好主意。请注意,您还替换了页面上的所有脚本,如果您的响应包含一些脚本,则无法加载。ajax的全部要点是保持在同一页面上。如果要返回整个视图,为什么要使用ajax?