I’m not convinced this is the cleanest way to do it but at least it work until I find something more efficient:
function json_gmap(){
$get_file = file_get_contents(get_template_directory_uri() . '/data/my.json');
$json_to_array = json_decode($get_file,true);
die (json_encode($json_to_array));
}
add_action('wp_ajax_json_gmap', 'json_gmap');
add_action('wp_ajax_nopriv_json_gmap', 'json_gmap');
Basically I decode my Json file to an array and the re-encode it to have it available in admin-ajax.php.
Any improvement is welcome 😀
Thanks
Matth
Related Posts:
- ASP.NET MVC controller actions that return JSON or partial html
- How to cache json with wp-super cache
- Why use wp_send_json() over echo json_encode()?
- WordPress function that makes HTML safe to be sent via AJAX request
- Delete row of custom table in WordPress using AJAX
- WP REST API route request explain
- How to use wp_send_json_error?
- Most performant way of fetching remote API data?
- json encode not work in wordpress
- Unable to parse JSON response from wp_send_json_success [closed]
- Why Does WordPress not output admin-ajax.php path by default?
- Ajax store response json in variables
- How do I query posts by a sub value with the API?
- Cache wp-json/posts without a plugin?
- Exposing data using a custom WordPress API
- Save & Reset button in theme-option with Ajax (without refresh)
- merge wp rest api query to get posts per category does not work
- Upload data from weather station to WordPress Website
- Sql formatting for post data within function
- How can I wp_send_json data?
- Full Front End, AJAX comment system and comment reply script
- Send checkbox status with Ajax / JSON and save it
- Chained ajax call, second call returns 0
- Can’t add classes using jQuery from a JSON string with get_body_class()
- Display full WordPress post under search form using AJAX
- Can I use application/json content type in WordPress
- Using wp_send_json_success instead of $result[‘message’], die, etc
- AJAX POST Value not being returned – WordPress – AutoTrader API
- Ajax call works for logged in users and returns “Bad Request” for guests [duplicate]
- How to inject data content from external json into a modal, using UIkit?
- how to correctly use json_encode with ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- 403 error for ajax POST request
- Ajax WordPress pass post URLs
- Jquery wrap permalink in a data-attribute?
- How to populate data from JSON using AJAX in TypeScript? [closed]
- AJAX save options inside class
- WordPress Ajax JSON success return no being recognized
- Ajax contact form returnig 0
- AJAX Call in Plugin Returns More than JSON
- Usage of wp_send_json_success and wp_redirect at the same time
- register_setting and AJAX?
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- jQuery’s .on() method combined with the submit event
- Why use admin-ajax.php and how does it work?
- Why is die() used at the end of function that handles an Ajax request?
- admin-ajax.php doesn’t work when using POST data and Axios
- Custom Form with Ajax
- How is it possible that the function of the test page works, but it does not go live?
- Adding callback function for wp_ajax_ has no effect
- jQuery Autocomplete not working with wp_localize_script
- How to add default images into theme customizer image control?
- Ajax returning correct data BUT at wrong place
- admin-ajax.php mixed content
- WP-API and Basic Auth returning 403 on POST but not GET
- Call javascript function when category was added via ajax
- Ajax in plugin settings page returns 400 Bad Request
- Viewing checkout page removes fees from mini cart
- Admin-Ajax Error
- WordPress Ajaxify Problem with Scroll-to [closed]
- Stop ajax listener from sending empty parameter to function
- Creating an auto result search bar
- update_option is not saving an array, but saving the string ‘Array’
- Ajax call in wordpress not working for subscriber user
- Need help with ajax
- How to retrieve WP_Object that is inside an array of another array
- What WP-API authentication method should I use to interact with anonymous / not-logged visitors?
- How to call ajax in plugin file
- Custom field bug in WordPress 3.2
- Get title and featured image using Ajax
- Search for custom field input of a custom post type in ajax live search
- Adding LOAD MORE on a page
- WP_Query is not received in Ajax
- My function containing a mysql query launched by ajax is not working in wordpress. What am I missing?
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- Updating Jquery object with newly created elements after AJAX call
- Wp admin ajax load more
- wordpress ajax search posts
- Ajax call from Plugin using Class
- Ajax by worpdress affects called jquery inside template file
- AJAX form not working, still reloads on submit
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Is there a best practice, or typical way to do AJAX updating for data on a custom admin screen or post.php?
- Edit user meta on front-end via AJAX
- Having a self updating list
- Unexpected WordPress search results
- WordPress Get Header and Footer using in Admin Area
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- jQuery AJAX add json2 dependency?
- ajax page template
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- Why does my Ajax Get request give a 400 bad request?
- Translating wordpress foreach to ajax
- AJAX loading with custom parameters
- Placing ajax actions in different class
- How to update my jquery/PHP function to add/remove user as favorites in (WordPress) users list