检查控制器的“ok”响应

I write come code with php, then i convert response in json. How i can check data from this response if ajax function. For example

$.ajax({
   method: "POST",
   dataType: "json",
   data: user,
   url: {{ path("indexAction") }}
}).done(function(data){
           if(data['ok']){  // this does not work
              var message = $('#message');
              message.css("background","white");
              message.css("display", "block");
           }
  });

If i alert(data) i have such data {"status":"ok","role":"user"}. My question is how check my data for status "ok"?

Since the returned data is an json object you can check the status like this:

if(data.status == "ok") {

}

If you just change your

if(data['ok']){

to

if (data["status"] == 'ok') 

then it should work.

Use data.status to access the status. And then

if(data.status == 'ok')

you can do ur logic

Please replace following code:

$.ajax({
   method: "POST",
   dataType: "json",
   data: user,
   url: {{ path("indexAction") }}
}).done(function(data){
           if(data.status == 'ok'){  // data['ok'] replace this
              var message = $('#message');
              message.css("background","white");
              message.css("display", "block");
           }
  });