I am using jQuery Spectrum and trying to call another function when a color is changed.
The other function has an ajax call, however, and when it runs, I get this error:
spectrum.js?ver=1.0.7:1277 Uncaught TypeError: Cannot read property 'getBrightness' of undefined
I assume it has something to do with the synchronicity of the calls, but am not sure how to resolve it.
jQuery('#mydiv').spectrum({
preferredFormat: "rgb",
showAlpha: true,
showPalette: true,
showInitial: true,
showSelectionPalette: true,
palette: ['rgba(0, 0, 0, 0)'],
showInput: true,
allowEmpty: true,
move: function(c) {
my_function(c);
},
change: function(c) {
my_function(c);
}
});
Then the function I am calling is this:
function my_function(color) {
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
datatype: 'JSON',
data: {
action: 'update_data',
color: color,
},
success: function(data) {
}
});
}
Is there anything I can do to make this work properly?
Here is a JSFiddle that provides the error as well: