This is really puzzling me. I have function defined in main.js file, which is loaded in the header, and then latter on I am calling that function at the end of HTML code. In Chrome I am getting error Uncaught ReferenceError: delete_image is not defined, but in Firefox it is working normally (same error is appearing in Opera). What is going on?
Function:
function delete_image(button, data = false){
button.on('click', function(){
var $this = $(this),
url = $(this).attr('href');
if( data == 'tmp' )
{
data = 'id=' + $this.data('id');
}
else if ( data == true )
{
data = forma.serialize();
}
$.confirm({
'title' : 'Image Delete',
'message' : 'Do you want to delete this image?',
'buttons' : {
'Yes' : {
'class' : 'blue',
'action': function(){
$.post(url, data, function(){
$this.parent().slideUp('slow');
});
}
},
'No' : {
'class' : 'gray',
'action': function(){}
}
}
});
return false;
});
};
Calling the function (after HTML part of the code):
<script>
var link = $('a[role=delete]');
delete_image(link);
</script>
You can't pass a default argument value in standard javascript today, this is invalid in Chrome :
function delete_image(button, data = false){
What you should do is
function delete_image(button, data){
if (data == undefined) data=false;
The MDN precises in what browsers you can use this feature (answer : only Firefox).
This should be available with Harmony. Here's some detail about ES6's plan.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With