[英]Server does not receive data from ajax call
I have a problem. 我有个问题。 I'm trying to send content of a textarea with an ajax call, but it doesn't seem to be working, and I don't know why. 我正在尝试通过ajax调用发送textarea的内容,但是它似乎没有用,我也不知道为什么。
There's the method called GetStatus(string statusText)
which need to receive the content. 有一种称为GetStatus(string statusText)
的方法,该方法需要接收内容。
Here's the javascript code: 这是JavaScript代码:
$("#btnSaveStatus").on("click", function () {
var statusText = $(".textareaEdit").val();
$.ajax({
type: "GET",
url: "Default.aspx/GetStatus",
data: "{statusText:'" + statusText + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
// $('#littlbioID').text(result.d);
}
});
});
Please advise. 请指教。 You should also know that I'm new into web development. 您还应该知道,我是Web开发的新手。
Generate your JSON programatically. 以编程方式生成JSON。
{
type: "POST",
url: "Default.aspx/GetStatus",
data: JSON.stringify({
statusText: statusText
}),
// etc
Obviously, the server side of the process needs to be set up to accept a POST request with a JSON body (instead of the more standard URL Form Encoded format) as well. 显然,还需要将流程的服务器端设置为接受带有JSON主体(而不是更标准的URL表单编码格式)的POST请求。
Try this: 尝试这个:
$("#btnSaveStatus").on("click", function () {
var statusText = $(".textareaEdit").val();
var jsonText = new Object();
jsonText.statusText = statusText;
$.ajax({
type: "POST",
url: "Default.aspx/GetStatus",
data: JSON.stringify(jsonText);,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
// $('#littlbioID').text(result.d);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.