Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

TypeError: blockUI.block is not a function



$("#view").on("show.bs.modal", function (e) {
var uuid = $(e.relatedTarget).data("id");
var target = document.querySelector("#kt_block_ui_1_target");
var blockUI = new KTBlockUI(target,
{
message: "<div class="blockui-message"><span class="spinner-border text-primary"></span> Loading...</div>",
});

$.ajax({
url: ""xxxxxxxx,
method: "GET",
dataType: "JSON",
beforeSend: function () {
blockUI.block();
},


what am i doing wrong please...
This throws TypeError: blockUI.block is not a function error please help


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Hi,

Please declare the blockUI variable in the global scope in order to access it in the callback function.
So you just need to declare var blockUI; outside the modal callback functions and use it inside the callback.

For more info please check the KTBlockUI documentation here.

Regards,
Sean



Hey Sean,

I have dynamically created elements (repeater) where I want to use blockUI. So defining the blockUI outside doesn't work here.

I run it inside a listener filter_data_select.addEventListener('change', handle_change()) but it doesn't work if it's called inside listener.



Looks like the problem is about defining KTBlockUI on the same element multiple times. I fixed the issue by checking if the instance is created first then defining if the result is null.

var blockUI = KTBlockUI.getInstance(target);


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic

React Dev Vacancy

KeenThemes is looking for a Junior React or Vue developer to build awesome apps.
Apply