I have ajax function whic is used to return current data time and then assign it to text box in asp .net for that I have Web method as follows (in .cs files)
[System.Web.Services.WebMethod]
public static string GetCurrentTime()
{
return DateTime.Now.ToString();
}
in head section i have following files included
<pre> <link href="../Css/bootstrapForNB.css" rel="stylesheet" />
<link href="../dist/navbar.css" rel="stylesheet" />
<link href="../Css/font-awesome.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
What I have tried:
I have aspx page on which one text box and one button control when I click on button control for first time then It show time in text box than after each 10 second it call to method to get time
<pre><div>
<ul>
<li id="noti_Container" class="nav-item">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="btnGetTime" type="button" value="show current time" />
<img src="../images/msg_Icon.png" id="noti_Button" />
</li>
</ul>
</div>
ajax function and call is as follows
<script type="text/javascript">
$(document).ready(function () {
alert('hi');
$("#btnGetTime").click(function () {
alert('hi');
setInterval(ShowCurrentTime(), 10000);
});
});
function ShowCurrentTime(e) {
alert('show time function');
$.ajax({
type: "POST",
url: "Analysis.aspx/GetCurrentTime",
data: {},
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function OnSuccess(response) {
$("#TextBox1").val(response.d);
},
failuar: function (response) {
alert(response.d);
}
});
}
when I click on button It is showing
alert('show time function');
but It is not hitting to Web method where I put break point
when I inspect Element it show following error
Uncaught TypeError: $.ajax is not a function
also
Failed to load resource: net::ERR_EMPTY_RESPONSE
please help me I am trying this function from last 2 days.