嗨,我使用Ajax Jquery调用C#函数,但它正在抛出内部服务器错误。帮助我...我的代码如下 [英] Hi I Am Using Ajax Jquery For Calling C# Function But It Is Throwing Internal Server Error.Help Me..My Code Below

查看:83
本文介绍了嗨,我使用Ajax Jquery调用C#函数,但它正在抛出内部服务器错误。帮助我...我的代码如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

window.setInterval(function(){

var currenttime = $('#Label1')。val();

var duration = $('#Label2 ').val();



$ .ajax({

类型:GET,

contentType:application / json; charset = utf-8,

url:videoplayer.aspx / UpdateTimer_Tick,

data:{'currenttime':' + currenttime +','duration':'+ duration +'},

async:false,

成功:函数(响应){





},

错误:function(){



}

});



},3000);













和C#功能



[WebMethod]

[ScriptMethod]

protected static void UpdateTimer_Tick(string currenttime,string duration)

{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings [myConnectionString]。ConnectionString);

试试

{

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(例外ex)

{

throw(ex);

}

}

解决方案

('#Label1')。val();

var duration =


( '#Label2')。val();



.ajax({

type:GET ,

contentType:application / json; charset = utf-8,

url:videoplayer.aspx / UpdateTimer_Tick,

数据:{'currenttime':'+ currenttime +',' duration':'+ duration +'},

async:false,

成功:函数(响应){





},

错误:function(){



}

});



},3000);













和C#功能



[WebMethod]

[ScriptMethod]

protected static void UpdateTimer_Tick(string currenttime,string duration)

{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings [myConnectionString]。ConnectionString);

试试

{

conn.Open();

SqlCommand cmd = new SqlCommand(插入currenttimedata(当前时间,持续时间)值(@ name,@ age),conn);

cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue(@ name,currenttime);

cmd.Parameters.AddWithValue(@ age,duration);



cmd.ExecuteNonQuery();

conn.Close();



}

catch(例外情况ex)

{

throw(ex);

}

}

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);
}
}

解决方案

('#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);
}
}


这篇关于嗨,我使用Ajax Jquery调用C#函数,但它正在抛出内部服务器错误。帮助我...我的代码如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆