Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.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# 函数不';无法使用长输入参数_C#_Jquery_Asp.net_.net - Fatal编程技术网

C# 函数不';无法使用长输入参数

C# 函数不';无法使用长输入参数,c#,jquery,asp.net,.net,C#,Jquery,Asp.net,.net,当输入字符串(#txtarea)包含少量字符时,Below函数起作用,但当它包含长字符串时,Below函数不起作用,如何使其工作 下面是我的代码: $('#insertcmt').click(function () { $.getJSON('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data)

当输入字符串(#txtarea)包含少量字符时,Below函数起作用,但当它包含长字符串时,Below函数不起作用,如何使其工作

下面是我的代码:

 $('#insertcmt').click(function () {
        $.getJSON('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data) {
        });
        loadcomments();

    });
服务器端逻辑:

    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public void InsertComment(string commenttext)
    {
        string sql = "INSERT statement";
        Database db = Utilities.GetDataBase();
        DbCommand cmd = db.GetSqlStringCommand(sql);
        db.ExecuteNonQuery(cmd);
    }

是因为我试图从跨域访问吗?

这可能是由于RFC GET请求中的限制造成的。看一看

由于您在服务器端逻辑中使用的是insert语句,所以无论如何都应该使用POST请求

 $('#insertcmt').click(function () {
    $.post('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data) {
    });
    loadcomments();
});
长URL(超过2000个字符)可能不适用于所有web浏览器

使用POST方法:

$('#insertcmt').click(function () {
  $.post('http://localhost:55679/RESTService.svc/InsertComment?callback=', 
    { commenttext: $('#txtarea').val() }, 
    function (data) {

    });

  loadcomments();
});
编辑:

您必须将[WebGet]属性更改为:

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]

尝试通过POST而不是GET发送内容,理论上没有通用的限制。

您需要显示服务器逻辑以及一些示例,说明它何时工作以及何时无法正确转义要在url中使用的字符串?@w.brian转义是什么意思?此函数转义文本var encoded=HttpUtility.HtmlEncode(未编码); var decoded=HttpUtility.HtmlDecode(编码)@但是您必须将attribute[WebGet]更改为[WebInvoke(Method=“POST”)]我将更改为[WebPost(ResponseFormat=WebMessageFormat.Json)],但它无法识别WebPost@Khan我已经编辑了我的评论,应该是[WebInvoke(Method=“POST”)]@Khan:可能是跨域请求引起的。一个常见的解决方案是使用jsonp。有关详细信息,请参阅:)但是,这也可能是服务器端问题。我不是一个asp开发人员,我真的不知道如何调试这个,对不起。