I want to implement a simple webpage using jQuery/Ajax. I have 3 buttons, each of which will use ajax call to get different files from the server. The only difference is that each button has different class name, and calls different files. Everything else, such as the loading time, loading icon, success/fail message, are all the same. Therefore, I would like to write only 1 ajax function, instead of 3.
I have:
<script>
$(document).ready(function(){
$(".button1").click(function(){
$.ajax({
url: "button1.txt",
/*more code*/
});
});
});
</script>
I want to create another function so that this "button1" and "button1.txt" will become a variable, and whatever is returned from the function will be used in the ajax function, in which way I can reuse the ajax function 3 times. How could you achieve this?
<button>elementshtmland correspondingjavascriptat Question? See stackoverflow.com/help/how-to-ask