The New Way to Build! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Learn More

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


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);



Can you describe more clearly the code you use? I had the same problem with

blockUI.realease();
when I call it on
success: (response) => {blockUI.realease();}


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(