Answer the question
In order to leave comments, you need to log in
How to get json content generated by php in WordPress CMS?
Good afternoon, the story is this - a multidimensional array is formed in php, serialized and placed in a file:
$serialArr = serialize($arr);
file_put_contents('cards.json', $serialArr);
$.getJSON('cards.json', function(data) {
var output = '<ul>';
$.each(data, function(key, val) {
output += '<li>' + val + '</li>';
});
output += '</ul>';
$("body").html(output);
});
Answer the question
In order to leave comments, you need to log in
$serialArr = serialize($arr);
Isn't it?$serialArr = json_encode($arr);
It must be placed in a directory accessible via the web. Those. if json-opens in the browser, then in the script too.
$.getJSON('cards.json' - instead of cards.json there should be a path from the address bar of the browser, because this is how it looks for this file from the current page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question