Addeventlistener with ajax not working well

前端 未结 2 787
花落未央
花落未央 2020-11-28 16:46

I want to show the content of a txt file inside a \'div\', so I\'m calling my function with a button, but the functions triggers even if I don\'t push the button, here\'s my

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 17:29

    The second argument to addEventListener should be a function. You're not passing a function, you're calling the function immediately and passing the result. Change to:

    document.getElementById("showF").addEventListener("click", function() {
        sacardatos('P1.txt','container');
    }, false);
    

提交回复
热议问题