JSON – Permission Error?

Your problem is that you are checking for nonce and the nonce is stale. It is hard to make a specific comment about the need of using nonce in your case, but in general nonces should be used only for data submission not query.

AngularJS with route and JSON API

Doublecheck if there’s a “nobase” error in your console. If so, according to the AngularJS documentation, and fix.io (credits for this answer go to the author of that post) the base tag is to the rescue. <html ng-app=”app”> <head> <base href=”https://wordpress.stackexchange.com/angular-wp/”> <title>AngularJS Demo Theme</title> <?php wp_head(); ?> Please note the “/angular-wp/” is the sub-context in … Read more

How to get those data using with ajax json?

There are two methods to access the object. 1. Ajax response. $.ajax({ url:”your_file.php”, type : “POST”, data : your_data, dataType: “json”, success:function(data){ // Retrieve the object var result = data[0]; // Grab username from the object console.log(result[‘username’]); }, error:function(xhr){ alert(‘Ajax request fail’); } }); 2. Server side script $yourArray = array(); $yourJson = json_encode($yourArray); $userData … Read more

How to syntax Json output for translation?

Technically, and this is highly discouraged do to it’s unfriendly and unpredictable nature, you can do this: <?php _e( $data[‘hair’][‘type’] ); ?> However, you’ll need to have all the possible values for that (“brown hair”, “blond hair”, etc.), listed in a .POT file (a translation template) so that translators know what to translate. You’ll need … Read more

Creating a Multi-Level Associative Object Using AJAX

If you want to pass a complex value, your best path is probably to jsonify it. Something like $.post( MyAjax.ajaxurl, { action: ‘my_action’, someValue: JSON.stringify({ one: ‘Some Value One’, two: ‘Some Value Two’, three: ‘Some Value Three’, four: ‘Some Value Four’, }) } ); and then on the server side you decode the value with … Read more