Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
                     setInterval(ShowCurrentTime(), 10000);
                 });
                
             });


             function ShowCurrentTime(e) {
                 //e.preventDefault();
                 alert('show time function');
                 //$.ajax({
                 $.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.
Posted
Updated 28-Mar-18 2:03am
v2
Comments
F-ES Sitecore 28-Mar-18 8:04am    
Start with the basics. Is that a valid url? Use the network tools of the browser to see the results of the request

https://forums.asp.net/t/1982579.aspx?Using+the+browser+s+dev+tools+to+diagnose+ajax+problems+and+other+things+
ZurdoDev 28-Mar-18 8:54am    
You are loading 2 jquery's. That's bad.

The error means it can't find jquery's ajax, probably have a conflict going on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900