[英]Passing value from multiline textbox using jQuery ajax
I would like to pass the content from a multiline textbox into an sql database using jQuery .ajax. 我想使用jQuery .ajax将内容从多行文本框中传递到sql数据库中。
function UpdateMemogramContent() {
$.ajax({
type: "POST",
url: "MemogramWebServices.asmx/UpdateMemogramContent",
data: "{ 'mId': " + $("#LabelId").text() + ", 'content': " + $("#TextBoxContent").text() + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
}
The problem I am facing is that the content from the multiline textbox is throwing an invalid json primitive exception. 我面临的问题是多行文本框中的内容引发了无效的json基本异常。 Taking a look at the POST: 看一下POST:
{ 'mId': 314, 'content': Test {'mId':314,'content':测试
Test} 测试}
What can I do to pass the text from a multiline textbox into an sql database using .ajax? 如何使用.ajax将文本从多行文本框中传递到sql数据库中?
Put a breakpoint before call posting data and look what value is you sending to server. 在呼叫记录数据之前放置一个断点,并查看您要发送给服务器的值。 Also 也
$("#TextBoxContent").text() $(“#TextBoxContent”)。text()
to 至
$("#TextBoxContent").val() $(“#TextBoxContent”)。val()
data: "{ 'mId': 数据:“ {'mId':
to 至
data: "{ mId: " 数据:“ {mId:”
Why not use an actual JavaScript structure like so. 为什么不使用这样的实际JavaScript结构。 This will however pass mId and content as standard post parameters rather than one piece of JSON. 但是,这会将mId和内容作为标准的post参数而不是一个JSON传递。
$.ajax({
type: "POST",
url: "MemogramWebServices.asmx/UpdateMemogramContent",
data: {
mId: $("#LabelId").text(),
content: $("#TextBoxContent").text()
},
...
});
Otherwise, you can also use JSON.stringify like so: 否则,您也可以像这样使用JSON.stringify :
var json_data = JSON.stringify({
mId: $("#LabelId").text(),
content: $("#TextBoxContent").text()
});
$.ajax({
type: "POST",
url: "MemogramWebServices.asmx/UpdateMemogramContent",
data: json_data,
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.