I would like to trigger button on document.ready() and do ajax call event on that triggered button event.
This is what I mean to say:
<script type="text/javascript">
$(document).ready(function () {
$("#btnLoad").trigger("click");
$("#btnLoad").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetDetails",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
}
});//ajax
});//btnClick
});//JQuery
Now my problem is I’m unable to trigger that button.
If I give a normal alert in the place of btn trigger it’s working fine.
Can anyone point out what the mistake is?
your trigger is called before bind, move the trigger after binding click handler.
Note: I have used
.click()to trigger click handler.