Search code examples
javaajaxjquery-callback

ajax callback data [object Object] instead of text


i want to catch the data from server as an answer and alert it. but it is alerting [object Object] instead of my answer text "very good". here is my ajax function:

 function ajaxsubmit(){
   $.ajax({
     url: "/update",
     type: "POST",
  }).complete(function(data) {
      alert(data);
  });
 }

and my serverside function is this:

public static Result ajaxupdate(){
    String done = "very good!";
    return ok(done);
}

do i have to cast the coming data with some other thing so that it prints the normal plain text?

thanks a lot


Solution

  • Return String. Try this..

    public static String ajaxupdate(){
        String done = "very good!";
        return done;
    }