Returning a view to an ajax call and replacing html page throws 'appendchild' exception in jquery

0

I'm making an ajax call like this below where I'm returning a view like this

return View("Finish");

This has the entire html page as a string as the response, so I want to replace the page with it, but when I do I receive an error

Unhandled exception at line 82, column 3 in https://localhost:44368/Scripts/jquery-3.1.1.js 0x800a138f - JavaScript runtime error: Unable to get property 'appendChild' of undefined or null reference occurred

Funny thing is it does set the html so I see the correct page on screen, I just see the exception in JQuery as well!

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");
  });
javascript
jquery
asp.net-mvc
asked on Stack Overflow Jun 27, 2018 by user1186050 • edited Jun 28, 2018 by user1186050

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0