parserrror SyntaxError: Unexpected token < - Load Partial View using jQuery Ajax in ASP.NET MVC 4

前端 未结 2 644
耶瑟儿~
耶瑟儿~ 2021-02-09 01:16

I\'m using the following Ajax call to load a partial view into a div:

  $.ajax({
    url: \"/URL\",
    type: \"POST\",
    dataType: \"json\",
    data: JSON.st         


        
2条回答
  •  孤街浪徒
    2021-02-09 01:39

    You need to change your datatype in the ajax call.

     dataType: "json",
    

    to

     dataType: "html", 
    

    Datatype tells that type is json, but you send back the partial view which is html. So it tries to parse it as json data and throws the error.

    datatype - type of data you expect back from the server.

    dataType (default: Intelligent Guess (xml, json, script, or html)) Type: String The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:

提交回复
热议问题