Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将jquery数据传递给WebMethod_Jquery_Asp.net_Webmethod - Fatal编程技术网

将jquery数据传递给WebMethod

将jquery数据传递给WebMethod,jquery,asp.net,webmethod,Jquery,Asp.net,Webmethod,我知道我们已经有很多关于这个主题的帖子,但我就是不知道如何将数据传递给WebMethod!我只需要将一个字符串数据传递给我的WebMethod,但我是否需要使用list数据类型 .js .aspx(用完整代码更新)//我注释掉了导致错误的部分 [System.Web.Services.WebMethod] void send (string text) { string id = HttpContext.Current.Request.Cookies["id"].ToString();

我知道我们已经有很多关于这个主题的帖子,但我就是不知道如何将数据传递给WebMethod!我只需要将一个字符串数据传递给我的WebMethod,但我是否需要使用list数据类型

.js

.aspx(用完整代码更新)//我注释掉了导致错误的部分

[System.Web.Services.WebMethod]
void send (string text) {
    string id = HttpContext.Current.Request.Cookies["id"].ToString();
    string queryString = "INSERT INTO Log (ID, Text, Date) Values (" + id + ", " + text + ", GETDATE())";
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=ChatV1;Integrated Security=True");
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(queryString, con);
    using (con)
    {
       con.Open();
       //cmd.ExecuteNonQuery();
    }
}

你做得对,你有什么问题?!我在chrome javascript控制台上收到500个internet服务器错误。我不能使用静态方法,因为我需要使用Request.Cookies集合来检索我的cookie。我发现我不能将集合与静态方法结合使用:(因此,请更改调用ajax请求的策略。使用PHP样式调用ajax请求(我的意思是使用其他网页并通过ajax请求调用它,而不是web方法)@SiYoungKim您是否尝试过HttpContext.Current.Request.Cookies以静态方法访问Cookies集合?@AliForoughi多亏了JQone,我可以将其设置为静态,现在它似乎工作了!除了在我的webmethod.cmd.ExecuteOnQuery中包含cmd.ExecuteOnQuery!!?需要更多详细信息
[System.Web.Services.WebMethod]
void send (string text) {
    string id = HttpContext.Current.Request.Cookies["id"].ToString();
    string queryString = "INSERT INTO Log (ID, Text, Date) Values (" + id + ", " + text + ", GETDATE())";
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=ChatV1;Integrated Security=True");
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(queryString, con);
    using (con)
    {
       con.Open();
       //cmd.ExecuteNonQuery();
    }
}
[System.Web.Services.WebMethod]
public static void send (string text) {
    string id = HttpContext.Current.Request.Cookies["id"].ToString();
    string queryString = "INSERT INTO Log (ID, Text, Date) Values (" + id + ", " + text + ", GETDATE())";
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=ChatV1;Integrated Security=True");
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(queryString, con);        
       con.Open();
       cmd.ExecuteNonQuery();
       con.Close();
}