阿贾克斯成功的功能为打印而不是纯文本[对象的对象。为什么?对象、而不是、文本、功能

2023-09-10 19:20:49 作者:锦书念伊安.

jQuery的code:

jQuery code:

function ajaxsubmit(){
$.ajax({
    url: "/update",
    type: "POST",
    dataType: "html"
}).success(function(data) {
      $('#result').html(data);
  });
}

和我的Java功能:

public static Result ajaxupdate() {
    String done = "very good";
    return ok("very good").as("text/plain");
}

警报是给 [对象的对象] ,而不是纯文本非常好。为什么?

the alert is giving [object Object], instead of plain text "very good". why?

推荐答案

添加数据类型:文字,改变完整的()成功()

add dataType: "text" and change complete() with success()

function ajaxsubmit(){
    $.ajax({
        url: "/update",
        type: "POST",
        dataType: "html"
    }).success(function(data) {
          $('#result').html(data);
      });
    }