[英]Function doesn't work with long input parameter
Below function works when the input string (#txtarea) contain few characters but doesn't work when it contain long string, how to get it working? 当输入字符串(#txtarea)包含很少字符但在包含长字符串时不起作用时,下面的函数有效,如何使它工作?
below is my code: 下面是我的代码:
$('#insertcmt').click(function () {
$.getJSON('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data) {
});
loadcomments();
});
server side logic: 服务器端逻辑:
[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);
}
Is it because i am trying to access from Cross Domain? 是因为我试图从跨域访问?
This is probably caused by the limitation in the RFC GET request. 这可能是由RFC GET请求的限制引起的。 Take a look at this question . 看看这个问题 。
Since you are using an insert statement in your serverside logic, you should probably use a POST request anyways. 由于您在服务器端逻辑中使用了insert语句,因此您应该使用POST请求。
$('#insertcmt').click(function () {
$.post('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data) {
});
loadcomments();
});
Long URL (over 2000 characters) may not work in all web browsers. 长URL(超过2000个字符)可能无法在所有Web浏览器中使用。
Use a POST method: 使用POST方法:
$('#insertcmt').click(function () {
$.post('http://localhost:55679/RESTService.svc/InsertComment?callback=',
{ commenttext: $('#txtarea').val() },
function (data) {
});
loadcomments();
});
Edit: 编辑:
You'll have to change the [WebGet] attribute to: 您必须将[WebGet]属性更改为:
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
尝试通过POST发送内容,而不是GET,理论上没有普遍的限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.