Ajax jquery success: funtion execute a function

2
success:function(data) {
        $('#login').val("Login");
        if (data=="1") {
         $(location).attr('href','index.php');

        } else {
          swal("Error", "Datos Icorrectos)", "error");
        }
      }

I want to show the following code in the html after the success

$.notify({
  message: 'Hello World' 
},{
  type: 'danger'
});
    
asked by Josbert Hernandez 03.08.2016 в 00:31
source

2 answers

1

here the solution: use $ (element) .text (); of jQuery to show html or javascript code

success:function(data) {
    $(elementoHTML).text("$.notify({message: 'Hello World' },{  type: 'danger'});");
    $('#login').val("Login");
    if (data=="1") {
     $(location).attr('href','index.php');

    } else {
      swal("Error", "Datos Icorrectos)", "error");
    }
  }

Greetings ...

    
answered by 03.08.2016 в 00:57
0

The success() method is obsolete from jQuery 3.0, so I suggest you use done() .

Keeping in mind that you are using the notify.js plugin, you do not need to include the script tags, which I assume you want to execute when the Ajax request is successful:

$.ajax('...').
  done(function(data) {

    $.notify({
      message: 'Hello World' 
    },{
      type: 'danger'
    });

    $('#login').val("Login");
    if (data=="1") {
      $(location).attr('href','index.php');
    } else {
      swal("Error", "Datos Incorrectos)", "error");
    }
  });
    
answered by 03.08.2016 в 02:27