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?
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();
});
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)]
尝试通过POST发送内容,而不是GET,理论上没有普遍的限制。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.