将json响应存储在变量中

时间:2012-06-19 11:21:53

标签: jquery

var response_data = jQuery.ajax({
    dataType: 'json',
    url: '/segments/'+ id + '/edit_user.json?context=' + context,
    type: 'POST',
    success: function(data){
      return data;
    }
  });
  if (response_data.warn_user == 'true'){
    return true 
  }else {
    warn_segment_edit('This field is presently being edited by ' + response_data.user_name + ' wait until editing is complete')
    return false 
  }

我收到此字段目前正由未定义编辑,等待编辑完成

有没有办法做到这一点。

由于

1 个答案:

答案 0 :(得分:0)

你可以这样做:

jQuery.ajax({
   dataType: 'json',
   url: '/segments/'+ id + '/edit_user.json?context=' + context,
   type: 'POST',
   success: function(data){
     if (data.warn_user == 'true'){
        return true;
     }else {
        warn_segment_edit('This field is presently being edited by ' +   data.user_name + ' wait until editing is complete');
        return false;
     }
   }
});