Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
window.setInterval(function () {
var currenttime = $('#Label1').val();
var duration = $('#Label2').val();

$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "videoplayer.aspx/UpdateTimer_Tick",
data: "{'currenttime':'" + currenttime + "','duration':'" + duration + "'}",
async: false,
success: function (response) {


},
error: function () {

}
});

}, 3000);






And C# function

[WebMethod]
[ScriptMethod]
protected static void UpdateTimer_Tick(string currenttime,string duration)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("Insert into currenttimedata (currenttime,duration) values(@name,@age)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@name", currenttime);
cmd.Parameters.AddWithValue("@age", duration);

cmd.ExecuteNonQuery();
conn.Close();

}
catch (Exception ex)
{
throw(ex);
}
}
Posted
Comments
ZurdoDev 26-Mar-15 14:04pm    
And the error is?
RajkumarGnanaraj 26-Mar-15 14:05pm    
I checked in google chrome.internal server erroe 500 failed to load resource
RajkumarGnanaraj 26-Mar-15 14:06pm    
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
jquery-2.1.1.min.js:4 GET http://localhost/findingproject/videoplayer.aspx/UpdateTimer_Tick?{%27currenttime%27:%27%27,%27duration%27:%27%27} 500 (Internal Server Error)
jquery-2.1.1.min.js:4 GET http://localhost/findingproject/videoplayer.aspx/UpdateTimer_Tick?{%27currenttime%27:%27%27,%27duration%27:%27%27} 500 (Internal Server Error)
jquery-2.1.1.min.js:4 GET http://localhost/findingproject/videoplayer.aspx/UpdateTimer_Tick?{%27currenttime%27:%27%27,%27duration%27:%27%27} 500 (Internal Server Error)
jquery-2.1.1.min.js:4 GET http://localhost/findingproject/videoplayer.aspx/UpdateTimer_Tick?{%27currenttime%27:%27%27,%27duration%27:%27%27} 500 (Internal Server Error)
ZurdoDev 26-Mar-15 14:10pm    
Can you debug the code? Put a breakpoint in C# and see if it is called. It sounds like it may be an invalid url.

However, refer to http://api.jquery.com/jquery.ajax/ and change your error function to accept all 3 parameters. They will give you the details of what happened.
ZurdoDev 26-Mar-15 14:12pm    
You may also need to be encoding your values, for example if your times have colons (:) in them, so that the url is valid. encodeURIComponent(str)

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