This could be my mis-understanding but i wanted someone to explain what i miss here.
If i have the below implementation for placing POST request using Jquery, the request is not made till i execute "click" event.
$(document).ready(function(){
$("button").click(function(){
$.post("demo_test_post.asp",
{
name:"Donald Duck",
city:"Duckburg"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
However if i give the anonymous function a name by defining it seperately, Then the post request is tried to send even while loading the page.
<script>
$(document).ready(function(){
$("button").click(callFunction());
});
var callFunction = function(){
$.post("demo_test_post.asp",
{
name:"Donald Duck",
city:"Duckburg"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
};
</script>
Can someone explain me what i am lacking in my understanding. To me both should work the same way
Thanks for reading
callFunctioninstead of just referencing it.