-2

My code is getting this error:

$.alert is not a function

I use jQuery from a CDN and jquery-confirm to run code. The first $.alert after document.ready works fine, after Btnsend.click it does not work.

$(document).ready(function(e) {
  $.alert('Teste Jquery-confirm'); // works
  var unidade = "<?php print $unidade ?>";

  $('#btnsend').click(function() {
    $.alert('clicado'); // error
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 1
    Check the console for errors. Most likely the output from `` is breaking the JS because it contains a double quote character – Rory McCrossan Jan 14 '21 at 14:30
  • Php print $ unit?> Working perfectly, I changed the first $ .alert to after the unit var ..... and it worked perfect, I even changed it to print the unit value and it worked .. – Draco Hellgate Jan 14 '21 at 14:58
  • Did you try without $, just: alert('blah')? – Don Ha Jan 14 '21 at 15:01
  • 1
    Don, the question I need to make work as $ .alert (), the alert () does not have a good presentation. And the big question is ... because it works before the click () and it doesn't work after .. – Draco Hellgate Jan 14 '21 at 15:04
  • 1
    We'll need to see this "in action" to determine the cause, there's no obvious way to know from the tiny amount of code provided. Have a read of [mcve] and [how to create a snippet](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do). – freedomn-m Jan 14 '21 at 15:40
  • The error you've stated normally indicates that jquery is being reloaded between the two invocations, but this seems unlikely given it's in doc.ready. – freedomn-m Jan 14 '21 at 15:41
  • a friend of mine tried some things here by the teamviewer and also can't identify because in the event of the click () button the cdn doesn't load or apparently unloads the information, the only peculiarity that I didn’t inform you is that this code runs inside an iframe, so I don’t know if loading the cdn of the index page is affecting it, but for testing I also adjusted the cdn of the index page with jquery-confirm and the first one works, but the second inside the button does not rotate. – Draco Hellgate Jan 14 '21 at 16:27

1 Answers1

-2

use Javascript alert() function, so:

$(document).ready(function (e) {
    alert('Teste Jquery-confirm'); // works
    var unidade = "<?php print 'unidade'; ?>";

    $('#btnsend').click(function () {
        alert('clicado');
Tech Spot
  • 464
  • 3
  • 10
  • 1
    this is exactly the command I don't want to use, the presentation is horrible, it needs to be a more presentable modal than the alert (); – Draco Hellgate Jan 14 '21 at 14:55
  • 1
    what I want to understand is why the first $ .alert () works perfectly and the second below the click () function jquery will not even by decree .. – Draco Hellgate Jan 14 '21 at 14:59
  • What are you saying? not exist a function called alert in jQuery. Read jQuery documentation before posting this kind of comments. https://api.jquery.com/jQuery.browser/#example-1 – Tech Spot Jan 14 '21 at 15:26
  • 2
    come on, my problem is with the jquery-confirm, it is in the title, if I am not going to change it, what I need to know is why the first code works $ .alert () and after the click () event it stops .. – Draco Hellgate Jan 14 '21 at 15:30
  • there are not possible the first $.alert works. Uncaught TypeError: $.alert is not a function. try yourself: https://jsfiddle.net/z2d9gvoc/ – Tech Spot Jan 14 '21 at 15:33
  • 1
    @TechSpot updated your fiddle: https://jsfiddle.net/m487dsfz/ Don't forget to check which [tags] op has used – freedomn-m Jan 14 '21 at 15:56
  • https://jsfiddle.net/t7gj8upf/1/ works fine, @Draco Hellgate I think you have some syntax error before brackets closing. – Tech Spot Jan 14 '21 at 16:01
  • so, just that my code is identical to this one, and I can only execute the first $ .alert, the second in the click () event does not work, I already checked the syntax – Draco Hellgate Jan 14 '21 at 16:30
  • so, paste complete code – Tech Spot Jan 14 '21 at 16:42
  • post all code in link jsfiddle.net, but not work simulate, – Draco Hellgate Jan 14 '21 at 17:07
  • it must really be an error caused by using iframe, or trying to perform a jquery-confirm inside a jquery. if there is no one specialized in jquery-confirm to see if this is a limitation of this package I believe that I will have to use a modal to not waste too much time. – Draco Hellgate Jan 14 '21 at 17:11