When you register the setting in JS, you need to supply the current value saved in the DB as the value, not some default value. So instead of:
var setting = new api.Setting( 'mySetting', 'JS Default Value?' );
You would need to obtain the value via some means like the REST API and then use it when instantiating. You also need to provide the transport. So it would look like this:
var setting = new api.Setting( 'mySetting', someResponse.value, { transport: 'postMessage' } );
Here are some examples of doing this:
Related Posts:
- Is it Possible to Extend WP Customize JS Methods?
- Customizer JS API: Defining control settings
- Customizer JS API: Adding a “dropdown-pages” control
- WordPress customizer get control
- Get a default value of the Customizer setting using wp.customize API (JS)
- Customizer JS API: Defining active_callback for a section
- Show sections based on a control in WordPress Customizer using JS API
- How do I add a class to Customizer preview based on class of Customizer control? (Customizer Javascript API)
- Get a default customizeAction text for a section using Customizer JS API
- Youtube api – stop video
- TypeError: res.status is not a function
- WP Rest API – How to get featured image
- Customizer JS API
- wp.customize.bind ready event not fired
- Show only images and videos in a wp.media window
- WordPress Rest API
- Is it possible to enqueue the Youtube API script or does it have to be inline?
- Detecting WordPress Customizer Panel
- WP Customizer set a value via javascript (to create presets)
- wp_customize_support_script – do I need it?
- Customizer – instantiating settings and controls via javascript
- Headless WordPress: How to authenticate front end requests?
- Customizer: When to use customize_preview_init VS customize_controls_enqueue_scripts
- Is there a client side API for handling transients or options?
- How to overwrite JS variable with wp_localize _script?
- Theme Customiser not live previewing changes on pseudo elements
- Hide/show customizer controls based on other settings in Customizer
- the Customizer – proper way to instantiate an image upload control via javascript
- Preserve Javascript Through Customizer Preview Navigation
- How to check if customize previewer is refreshing?
- JavaScript in WordPress Customizer
- Accessing customizer values in javascript
- Running JS after theme customizer finished initialization
- customize_preview_init: listening for any changes from Customizer preview area
- How to disable inline css styles generated by Gutenberg editor?
- How to conditionally show/hide controls & sections in WordPress customizer?
- Multiple Conditional Controllers
- Using webpack to add customizer live preview functionality – wp.customize is not a function
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- How to add customizer control via javascript ( wp.customizer.control.add )
- Load page in customizer preview on panel click?
- I am trying to add current logged in user to my zoho chat
- This page can’t load Google Maps correctly [closed]
- Adding Code into Theme Customizer Header
- Custom JS text area in customizer is being formatted wrong in document
- customize-controls.js – extend api.previewer
- how to use nimble-API and Display data?
- create timestamp links to jump to specific times on rumble videos
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- WordPress Guternberg Content For React Native
- I would like to retrive JSON value and display it in wordpress page or widget
- LayersWP Customizer White Blank Screen
- Create new product with woocommerce REST API with javascript (clientside)?
- Receive “menu-toogle” event from section menu in customizer
- Anyway to disable the auto excerpt creation?
- Retrieve customizer value using ajax or customizer api and print the value in theme
- Adding javascript blocks to a single file and adding it to the header
- None of the JavaScript works when using wp_editor
- JS files landing on page but not working, using childtheme of twentyeleven
- WordPress 4.1 crashes loading of ArcGIS Javascript API
- jQuery + more won’t load in header
- How to modify a class in load-scripts.js ?
- Convert javascript running xml files to wordpress platform
- WOW.js Script Tag Initialization Header/Footer
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Remove WordPress default registration client side validation?
- How to integrate a different (JavaScript) editor in WordPress?
- JS enqueue path (localhost)
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Load and execute javascript from body
- Why can’t I load JS script in a plugin?
- Page template dynamic links based on browser size
- javascript errors on mobile browser, not on desktop
- 3.5.x Theme Customize: Handling Custom Control Requests
- Trigger a function during onload
- Loaded JavaScript file not showing [duplicate]
- WordPress Theme – jQuery JavaScript Library Issue
- I keep getting Javascript error messages
- How to add additional JavaScript code [duplicate]
- custom page url slug needs illegal ?id=1 for javascript
- Script loaders vs wp_enqueue_script
- PHP or JS for header image rotator?
- convertEntities() used before it is defined
- Block pattern conflict with custom block
- Use one javascript variable into another javascript file
- JavaScript: TypeError: xyz is not a function after upgrading WordPress
- How do I find stylesheet & javascript handles? [duplicate]
- JavaScript errors
- JavaScript file successfully registered but does not render correctly
- Don’t understand how to link Javascript files in WordPress
- How could I add load more posts to my theme? [closed]
- Disable PAGESPEED SCRIPT INJECTION to IMAGE in theme files [closed]
- How to Create a Repeatable Meta Box
- How to keep close a sub-menu under homepage? [closed]
- Custom JS doesn’t work after 4.9.9 update [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- Loading 2 Different Version of JS files [closed]
- List unused javascript for easy removal
- Embed Kajabi into WP