使用ajax将批量数组值传递给codebehind(cs) [英] Passing bulk array values to codebehind(cs) using ajax

查看:63
本文介绍了使用ajax将批量数组值传递给codebehind(cs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用ajax将批量数组值传递给cs后面的代码我已经研究了很多并使用了这段代码,但它对我来说不起作用是我在aspx中使用的代码 - 我需要的是我需要传递批量使用ajax在(cs)后面的代码中的数组值



我尝试过:



I have to pass bulk array values to code behind cs using ajax i had researched a lot and used this code but it didnot worked for me below is the code that i used In aspx- what i need is i need to pass bulk array values in code behind(cs) using ajax

What I have tried:

<script>
       function foo() {
           var values = ["1,", "2", "3"];

           // Make the ajax call
           $.ajax({
               type: "POST",
               url: "Default.aspx/Done", // the method we are calling
               contentType: "application/json; charset=utf-8",
               data: {values : JSON.stringify({ arr: values })},
               dataType: "json",
               success: function (result) {
                   alert('Yay! It worked!');
               },
               error: function (result) {
                   alert('Oh no :(');
               }
           });
           return false;
       }
</script>




</head>
<body>
    <form id="form1"  runat="server">
    <div>
   <asp:Button ID="Button1" runat="server" Text="Button"  UseSubmitBehavior="false" OnClientClick="return foo();" />
    </div>
    </form>
</body>

< br $> b $ b



protected void Page_Load(object sender, EventArgs e)
       {

       }
       public static class RouteConfig
       {
           public static void RegisterRoutes(RouteCollection routes)
           {
               var settings = new FriendlyUrlSettings();
               //settings.AutoRedirectMode = RedirectMode.Permanent;
               routes.EnableFriendlyUrls(settings);
           }
       }

       [WebMethod]
       public static void test(string[] arr)
       {

       }



使用此代码我在routes.EnableFriendlyUrls(设置)附近收到错误;但我仍然可以在我的网页上看到按钮,当我点击该按钮时,没有任何事情发生只有页面正在刷新,但我需要将批量数组值传递给后面的代码使用ajax


using this code i am getting an error near routes.EnableFriendlyUrls(settings); but still i am able to see button in my webpage and when i click on that button nothing happens only the page is getting refreshed but i need to to pass bulk array values to code behind using ajax

推荐答案

.ajax({
type: POST
url: Default.aspx / Done // 我们正在调用的方法
contentType: application / json; charset = utf-8
data:{values: JSON .stringify({ arr:values})},
dataType: json
成功: function (结果){
alert(' 是的!它奏效了!');
},
错误: function (结果){
alert(' 哦不:(');
}
});
return false ;
}
< / script>
.ajax({ type: "POST", url: "Default.aspx/Done", // the method we are calling contentType: "application/json; charset=utf-8", data: {values : JSON.stringify({ arr: values })}, dataType: "json", success: function (result) { alert('Yay! It worked!'); }, error: function (result) { alert('Oh no :('); } }); return false; } </script>




</head>
<body>
    <form id="form1"  runat="server">
    <div>
   <asp:Button ID="Button1" runat="server" Text="Button"  UseSubmitBehavior="false" OnClientClick="return foo();" />
    </div>
    </form>
</body>

< br $> b $ b



protected void Page_Load(object sender, EventArgs e)
       {

       }
       public static class RouteConfig
       {
           public static void RegisterRoutes(RouteCollection routes)
           {
               var settings = new FriendlyUrlSettings();
               //settings.AutoRedirectMode = RedirectMode.Permanent;
               routes.EnableFriendlyUrls(settings);
           }
       }

       [WebMethod]
       public static void test(string[] arr)
       {

       }



使用此代码我在routes.EnableFriendlyUrls(设置)附近收到错误;但我仍然可以在我的网页上看到按钮,当我点击该按钮时,没有任何事情发生只有页面正在刷新,但我需要使用ajax将批量数组值传递给后面的代码


using this code i am getting an error near routes.EnableFriendlyUrls(settings); but still i am able to see button in my webpage and when i click on that button nothing happens only the page is getting refreshed but i need to to pass bulk array values to code behind using ajax


试试这个



try this

var intArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];


.ajax({
type: POST
url: WebForm3.aspx / done
contentType: application / json; charset = utf-8,
data: JSON .stringify({ids:intArray}),
成功: function (data){},
failure: function (data){}
} );
.ajax({ type: "POST", url: "WebForm3.aspx/done", contentType: "application/json; charset=utf-8", data: JSON.stringify({ ids: intArray }), success: function (data) { }, failure: function (data) { } });


这篇关于使用ajax将批量数组值传递给codebehind(cs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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