The script doesn't work until I refresh the page[Nodebb-plugin]

NodeBB Plugins
  • I need to check some parameter when a user log in. I must check this parameters in real time. So i create a new file main.js in static/lib ( the script is declared in plugin.json):

    	var email_form=$('#email');
    	if(email_form!=null){
    			$('#email').on('input',function() {
    	console.log("IN");
    $.ajax({
    					url:'....',
    					data:{'email_input':s},
    					success: function(data) {
    
    					}
    					
    					});
    }~~~~            
    

    #email is the field of login in the nodebb forum. So if I come to login page from a url the script doesn't work(the ajax call is not called) but if I refresh the login page the script works.Anyone can help me?

  • This is because the form element doesn't exist when you initially load the page.

    Use the event selector on the body element to grab the form dynamically.

    $('body').on('input', '#email', function() {
        console.log("IN");
        $.ajax({
            url:'....',
            data: { 'email_input': $(this).val() },
            success: function(data) {
            }
        });
    
    });
    


Suggested Topics


| | | |