I am having trouble parsing my AJAX response from my WordPress API that my hybrid mobile app is making. Below is (one of many ways I have tried to parse the response all of which have not worked):
var $team_url = '/wp-json/wp/v2/team-post?_embed';
$.ajax({
url: $base_url + $team_url,
async: true,
dataType:'json',
type: 'GET',
beforeSend: function () {
$.mobile.loading('show');
},
complete: function (wpdata) {
$.mobile.loading('hide');
// var data = jQuery.parseJSON(wpdata);
// var data = JSON.stringify(wpdata);
//var items = '';
//THE LOOP BELOW SHOULD SHOW 10 POST IDS IN MY CONSOLE
$.each(wpdata, function(index, post) {
console.log(post.id);
});
// $("#artist-list").append(items);
},
});
When I check my network tab I am seeing the JSON and it is returning 0-9 post of my custom post type "team-post" but when I try to access the individual data from the response I am not having any luck.
If it helps I can post the many errors I keep getting whenever I try something different.
Below I have added another way I tried to loop through it and the error I got.
$.each(wpdata.responseText, function(index, post) {
console.log(post.id);
});
ERROR:
Uncaught TypeError: Cannot use 'in' operator to search for '31687' in [{"id":597,"date":"2019-12...
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744931750a4601782.html
评论列表(0条)