You can use wp_localize_script
to pass an object with the url to load before the file. and then in the file you can use it like testpage_obj.json_data
wp_register_script('testpage', get_stylesheet_directory_uri() . '/js/testscript.js', array('jquery'), '', true);
wp_localize_script( 'testpage', 'testpage_obj', array(
'json_data' => get_stylesheet_directory_uri() . '/js/mydata.json'
) );
wp_enqueue_script('testpage');
In the JS file
jQuery.getJSON(testpage_obj.json_data)
Related Posts:
- JSON parsing error syntax error unexpected end of input
- data.map is not a function
- Jquery Ajax Posting JSON to webservice
- TypeError: $.ajax(…) is not a function?
- jquery loop on Json data using $.each
- SON Post with Customized HTTPHeader Field
- jQuery posting JSON
- how to loop through JSON array in jQuery?
- Javascript : array.length returns undefined
- $(document).ready(function() is not working
- Can’t get a JSON object in response to an Ajax request with wp_ajax
- AJAX returns response 0
- How to Use JSON With AJAX?
- Cannot access elements of json object
- JSON output returns page source code [closed]
- How to get those data using with ajax json?
- Intergrating agile carousel to wordpress: how to write the ajax_callback function
- I want to import my Json file into a custom made display-modal. How do i link my Json file?
- Using WP_Query to grab custom meta values, foreach to json object
- How to retrieve WP_Object that is inside an array of another array
- Can’t add classes using jQuery from a JSON string with get_body_class()
- Parse wordpress blog data using json api and ajax
- Loop through WordPress API response errors
- How to send json data to jquery
- how to remove/exclude html coding from json file while export?
- Uncaught TypeError: Cannot read property ‘ajax’ of undefined
- jQuery AJAX add json2 dependency?
- getJSON on WordPress Page
- Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?
- speedtest.net api
- Nested JSON objects – do I have to use arrays for everything?
- jQuery Ajax error handling, show custom exception messages
- How to write jquery If else statement?
- Uncaught TypeError: data.push is not a function
- How to break out of jQuery each loop?
- jQuery Scroll to bottom of page/iframe
- How to call a webservice method from an html page [javascript] with out refresh the page
- Random background images CSS3
- $ not defined using jQuery in WordPress
- Passing boolean values with wp_localize_script
- Concatenate and minify dependencies for enqueued JavaScript files
- AJAX nonce with check_ajax_referer()
- Using ‘$’ instead of ‘jQuery’ in WordPress
- AJAX call returns 0
- Is it possible to get the logged in username in a jquery script?
- Gravity Forms loading jquery
- Extend 3.5 media uploader plugin to change button name
- Javascript included but alert() function not working
- Adding fields to the media uploader with jquery listeners
- Bind to WPSetAsThumbnail
- How do I activate jQuery/script on demand?
- How to delete post attachments when jQuery is used with a click event on the delete link
- adding google event tracking to links in posts
- how can I make $ work in wordpress for jQuery?
- Override default jquery ui library with newer version
- Can I make simple global tooltips in WordPress?
- WordPress Jquery Confliction with Plugin
- Unwanted content in website title
- HTML editor accessing quicktag buttons
- Error when posting comment form: The error is TypeError: e[h] is not a function
- How to use datepicker.min.js?
- Using Javascript to detect keypress event in text editor
- videopress videos are not displayed when loading the content with ajax in a lightbox
- Bypass nonce value while trashing a post
- Call a javascript function from another file
- Adding JS to one page
- Set TRUE or FALSE based on a wp_localize_script option value
- Display posts from another site using REST API in an asynchronous manner
- Simplest ajax form not working when it should
- Changing WordPress URL breaks some jquery functions
- Extend the twentyten dropdown menu with jQuery with a delay onmouseout
- Loading a newer version of jQuery within WordPress
- How to display comments length
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- Can’t execute jQuery before my script
- Admin Ajax is returning 0 and not Insert data
- Multiple Media uploader output to input
- Using WP functions inside javascript
- How to add external remote JS source to Gravity Forms?
- Why is ajax working on one server and not the next?
- Connect Agile Carousel to WordPress AJAX
- Calling multiple scripts using wp_enqueue_script
- jQuery forms & updating info
- How to use script in WordPress installation?
- JavaScript code do not works on online server
- How to add jQuery script?
- Displaying contents of a tab
- In the Edit Post page how do I modify with jQuery the status select list?
- Variable not being returned from Ajax Javascript (though javascript receives it)
- Append jquery script for each [partners] shortcode with specified values
- Infinite scroll page number [duplicate]
- Thumbnail remove width & height function
- How to install Lavalamp jQuery effect in wordpress [duplicate]
- How to Run a jQuery Script after a Javascript Script has Finished in WordPress
- Hook with jquery script is not working in wp-admin [closed]
- Uncaught TypeError: number is not a function [closed]
- Cannot get jQuery to work in WordPress [duplicate]
- Generate dynamic ID’s for each accordion button
- Impossible to update jQuery version from 3.1.0
- Enqueued jQuery not working