【发布时间】:2012-08-29 18:40:07
【问题描述】:
我想使用 Jquery 和 Ajax 将 Json 数据存储到表中。这是我的 Json 文件如下所示:-
[
{
"term": "BACCHUS",
"part": "n.",
"definition": "A convenient deity invented by the ancients as an excuse for getting drunk.",
"quote": [
"Is public worship, then, a sin,",
"That for devotions paid to Bacchus",
"The lictors dare to run us in,",
"And resolutely thump and whack us?"
],
"author": "Jorace"
},
{
"term": "BACKBITE",
"part": "v.t.",
"definition": "To speak of a man as you find him when he can't find you."
},
{
"term": "BEARD",
"part": "n.",
"definition": "The hair that is commonly cut off by those who justly execrate the absurd Chinese custom of shaving the head."
}
]
我有一个名为“json”的表,其中三列的名称分别为术语、部分和定义。现在我刚刚像这样将 json 数据加载到 html 表中。
$.ajax({
type: "GET",
url: "b.json",
dataType: "json",
success: function (data) {
$.each(data, function (entryIndex, entry) {
// var html = '<div class="declareing_variable">';
var html1 = entry['term'];
var html2 = '<div class="geting_part">' + entry['part'] + '</div>';
var html3 = '<div class="geting_definition">' + entry['definition'] + '</div>';
$('<tr></tr>').html('<th>' + html1 + '</th><th>$' + html2 + '</td><th>$' + html3 + '</th>').appendTo('#json');
$('#abc').append(html2);
});
}
});
谁能告诉我如何将它存储到 sql 表中并可以提供一些编码帮助?
【问题讨论】:
-
jQuery 不与数据库对话。而且 b.json 不太可能是真正的 url。你需要一种像 PHP 这样的语言来做到这一点。
-
实际上在asp.net C#项目中需要它。我希望我们可以在C#中做到这一点。 btw b.json 文件直接放在 current 中。
-
您需要再发送一个带有所需数据的 ajax 请求,因为 jQuery 无法直接与服务器通信。然后,您需要使用 sql 查询或存储过程将这些数据存储到数据库中。
标签: c# jquery asp.net json mysql