Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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
C# 如何在jquery中发送数组并在asp.NETC中获取#_C#_Javascript_Jquery_Asp.net - Fatal编程技术网

C# 如何在jquery中发送数组并在asp.NETC中获取#

C# 如何在jquery中发送数组并在asp.NETC中获取#,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,我有这个密码。 在页面lode中,我想发送2个val“名称”和“城市” 这是js代码的claint端 $(document).ready(function () { $.post("Default.aspx", { name: "Donald Duck", city: "Duckburg" }, function (data, status) { alert("Data: " + data + "\nStatus: " + status); });

我有这个密码。 在页面lode中,我想发送2个val“名称”和“城市”

这是js代码的claint端

$(document).ready(function () {

$.post("Default.aspx",
 {
     name: "Donald Duck",
     city: "Duckburg"
 },
 function (data, status) {
     alert("Data: " + data + "\nStatus: " + status);
 });

  });
在服务器端Default.aspx.cs中,我希望获得2 val“name”和“city”

这是发球区代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
{
    string id = Request.QueryString["name"];
    var status = Request.Form["city"];

    string fname = Request.Form["name"];
    string city = Request.Form["city"];


}
}

什么不起作用?

在类中创建一个方法:

public partial class Default2 : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {

   }

  [WebMethod]
   public static string TestingAjax(string name,string city)
   {
    return name;
   }

}
使用jquery ajax将其称为:

 $(document).ready(function () {

    var JsonData = JSON.stringify({ 
       name: "Donald Duck",
       city: "Duckburg"
});    
         $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "Default.aspx/TestingAjax",
        data:  JsonData ,
        dataType: "json",

        success: function(data) {

        console.log(data);

        },
        error: function(result) {
        alert("Error");
        }
        });
    });

什么不起作用?您是否尝试过从浏览器的开发工具中查看请求?您是否尝试在服务器上调试以查看这些变量值是什么?您需要在表单中创建一个web方法并调用该方法:Joe Enos在debugging all val is nullEhsan Sajjad中,我将您的建议复制到我的visual studio。看起来他现在不这么胡闹了。这里请创建问题的副本,尝试使用[System.Web.Services.WebMethod]或在文件中包含System.Web.Services(使用System.Web.Services;在文件顶部)@YehudaRaz您需要包括其名称空间OK i add System.Web.Services,但现在控制台中的lode alart error page页面=加载资源失败:服务器响应状态为500(内部服务器错误)