Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a method with 3 parameters which returns the data in JSON format.

-----------------------------------------------------------------------------------

[OperationContract]
        [WebGet(RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "/Get_myHours/")] 
        public string Get_myHours(int loginID, DateTime frmDate, DateTime toDate)
        {
            using (MyEntities OE = new MyEntities())
            {
                var jsonSerialiser = new JavaScriptSerializer();
                var json = jsonSerialiser.Serialize(OE.GET_HRbyIDdate(loginID, frmDate, toDate).ToList<GET_HRbyIDdate_Result>());
                return json;
            }           
        }

--------------------------------------------------------------------------------

i am calling this method 'Get_myHours' from html page which is in the same project.
its not working please help !!!

-------------------------------------------------------------------------------
    <script>
        function show() {            
        $.ajax({
            type: "GET",
            url: "Service1.svc/Get_myHours",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var result = data.Get_myHours(loginIDtxt, frmDatetxt, toDatetxt);
                var Days = result.Days;
                var FinalTime = result.FinalTime;                
                $('#jsonData').html('');
                $('#jsonData').append('<table><tbody><tr><th>' + 
                  'Days</th><th>FinalTime</th>' + 
                  '</tr><tr><td>' + Days + '</td><td>' + FinalTime +
                '</td></tr></tbody></table>');
            },
            error: function (msg) {
                alert("error")
            }
        });
    }
    </script>

   
 <div>
       <input id="loginIDtxt" type="text" />;
        <input id="frmDatetxt" type="text" />;
        <input id="toDatetxt" type="text" />t;
        <button onclick="show()">Enter</button>;        
   </div>
<div id="jsonData">

    </div>

-------------------------------------------------------------------------------------
Posted
Updated 21-Sep-15 21:40pm
v4
Comments
Ehsan Sajjad 22-Sep-15 5:15am    
you are not passing parameters of the service method from client side
[no name] 22-Sep-15 5:55am    
I am passing but its not hitting the method :(

1 solution

Change your ajax call code to:

JavaScript
$.ajax({
            type: "GET",
            url: "Service1.svc/Get_myHours",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: { loginIDtxt:loginIDtxt,
                    frmDatetxt:frmDatetxt,
                    toDatetxt:toDatetxt
                  },
            success: function (response) {
                
                var Days = response.Days;
                var FinalTime = response.FinalTime;                
                $('#jsonData').html('');
                $('#jsonData').append('<table><tbody><tr><th>' + 
                  'Days</th><th>FinalTime</th>' + 
                  '</tr><tr><td>' + Days + '</td><td>' + FinalTime +
                '</td></tr></tbody></table>');
            },
            error: function (msg) {
                alert("error");
            }
        });
 
Share this answer
 
Comments
[no name] 22-Sep-15 5:55am    
No its not hitting the method :(
Ehsan Sajjad 22-Sep-15 9:29am    
give complete url in url property like : "url : localhost/SomeProject/Service1.svc/Get_myHours",
[no name] 23-Sep-15 6:02am    
I gave http://localhost:51065/Service1.svc/Get_myHours
its not hitting, and i am using wcf service.
[no name] 23-Sep-15 6:03am    
do i need to change anything in config ?
Ehsan Sajjad 30-Sep-15 3:43am    
i don't think so.

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



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