在ASP.Net中获取发布数据 [英] Get post data in ASP.Net

查看:75
本文介绍了在ASP.Net中获取发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您阅读!

我正在尝试使用jquery的ajax方法向服务器发送一个长字符串(+4000个字符)。



对于我所读的内容,您可以使用javascript / jquery发布,如下所示:

Thank you for reading!
I'm trying to send a long character string (+4000 chars) to the server using jquery's ajax methods.

For what I read, you can post using javascript/jquery as in:

var poststring = "long +4000 char string";
                                
var options = {};
options.url = "Handler.ashx";
options.type = "POST";
options.contentType = false;
options.processData = false;
options.data = poststring;
options.success = function(result) {
                   //to be determined                  
                                }
                                
options.error = function(err) { alert(err.statusText); };

$.ajax(options); //AND FINALLY, THE DATA IS SENT!!





如何使用带C#的ASP.NET获取options.data的值?



How do you fetch the value at options.data using ASP.NET with C# ?

推荐答案

.ajax(options ); // 最后,数据发送!!
.ajax(options); //AND FINALLY, THE DATA IS SENT!!





如何使用带C#的ASP.NET获取options.data的值?



How do you fetch the value at options.data using ASP.NET with C# ?


试试这样



Html:



Try like this

Html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.8.2.min.js"></script>

    <script type="text/javascript">
        function SendDataToServerUsingAjax() {

            var poststring = "pass your text to the server";
            var parameters = JSON.stringify({ 'parameterName': poststring });


.ajax({
type:POST,
url :WebForm1.aspx / ServerMethodName,
data:parameters,
contentType:application / json; charset = utf-8,
dataType:json,
成功:function(response){

alert(response.d);
},
failure:function(response){
alert(response.d);
}
});
}

< / script >


< / head >
< 正文 >
< 表格 id = form1 runat = 服务器 >
< span class =code-keyword>< div >
< asp:按钮 文本 = 将数据发送到服务器 OnClientClick = SendDataToServerUsingAjax();返回false runat = server / >
< / div < span class =code-keyword>>
< / form >
< / body >
< / html >
.ajax({ type: "POST", url: "WebForm1.aspx/ServerMethodName", data: parameters, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert(response.d); }, failure: function (response) { alert(response.d); } }); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button Text="send data to server" OnClientClick="SendDataToServerUsingAjax(); return false" runat="server" /> </div> </form> </body> </html>







代码背后:






Code Behind:

[System.Web.Services.WebMethod]
       [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
       public static string ServerMethodName(string parameterName)
       {

           return "success";
       }


这篇关于在ASP.Net中获取发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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