从Ajax发布请求

时间:2019-04-20 04:10:02

标签: arrays json ajax object

我正在向内部PHP发送AJAX请求并接收回一个对象。该对象具有“数据”和“状态”的属性,但是当我尝试访问它们时,它不返回任何内容。如何分别显示每个属性?

作为参考,返回的obj数组为:

{"data:[{"tagId":"8787","tagDescription":"001","tagMin":"0","tagMax":"100"},{"tagId":"8729","tagDescription":"1","tagMin":"44","tagMax":"555"}]
function GetAll() {
  var PostRequest ={};
  PostRequest['tagId']= 'all';

  $.post('php here',PostRequest,ShowAllTags);
}


function ShowAllTags( responseData, responseStatus ) { 
  console.log(responseStatus);

  var tagData = {};
  tagData = responseData;
  console.log(tagData['data']);
}

enter image description here

1 个答案:

答案 0 :(得分:2)

所以根据我上面提到的评论,问题出在json对象。 因此,首先解决该问题,

将是该问题的通用解决方案;

var obj = [{"tagId":"8787","tagDescription":"001","tagMin":"0","tagMax":"100"},{"tagId":"8729","tagDescription":"1","tagMin":"44","tagMax":"555"}];



 obj.forEach(function(value, index){console.log(value.tagId)});

这可能有助于如何获取每个属性的价值