0

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?

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?

Khan
  • 41
  • 1
  • 8

3 Answers3

1

This is probably caused by the limitation in the RFC GET request. 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.

 $('#insertcmt').click(function () {
    $.post('http://localhost:55679/RESTService.svc/InsertComment?callback=?', { commenttext: $('#txtarea').val() }, function (data) {
    });
    loadcomments();
});
Community
  • 1
  • 1
Esben Tind
  • 885
  • 4
  • 14
  • @Khan: Maybe that is caused by a cross-domain request. A common solution is using jsonp. See [this answer](http://stackoverflow.com/a/3506306/473475) for details on this :) However, this might also be a serverside issue. I am not an asp developer, and I don't really know how to debug this, sorry. – Esben Tind Mar 21 '13 at 21:32
1

Long URL (over 2000 characters) may not work in all web browsers.

Use a POST method:

$('#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:

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Corneliu
  • 2,932
  • 1
  • 19
  • 22
0

Try sending the content via POST, rather than a GET, there's no universal limit in theory.

Andrew Beal
  • 427
  • 8
  • 23