我有一个文本框。在它的输入中,我想保存它的数据,就像粘性笔记,我指的是asp.net中的自动保存文本框。
我的前端代码是:
<textarea id="txtClientArea" runat="server" class="scfMultipleLineTextBox" cols="20" rows="4" onchange="onTextChange" >
我的javascript方法是:
function onTextChange(data) {
debugger;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "StickyNote.aspx/SaveData",
data: JSON.stringify({ "data": data }),
datatype: "json",
async: false,
success: function (response) {
alert("C# method calling : " + response.d);
},
error: function (err) {
alert(err.responseText);
}
});
}方法背后的代码是:
[System.Web.Services.WebMethod]
public static void SaveData(string data)
{
User currentUser = Sitecore.Context.User;
if (currentUser != null)
{
currentUser.Profile.SetCustomProperty("StickyNote", data);
}
}如何使文本框数据自动保存?
发布于 2015-01-19 12:06:15
您可以尝试以下几种方法:
$('#<%=txtClientArea.ClientID%>').on('change',function () {
var data = encodeURIComponent($(this).text());
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "StickyNote.aspx/SaveData",
data: JSON.stringify({ "data": data }),
datatype: "json",
async: false,
success: function (response) {
alert("C# method calling : " + response.d);
},
error: function (err) {
alert(err.responseText);
}
});
});https://stackoverflow.com/questions/28023814
复制相似问题