我试图使用 html 5 使页面内容可编辑,并将数据保存在 json 文件中以备后用。
我还想如果页面加载使用 AJAX 只是被编辑的部分和修改 json 文件的 php 文件。
对此的任何投入都会非常有帮助。
到目前为止,我已经从头开始 AJAX 浏览了 AJAX PHP JSON,并且对它有很好的了解,但我需要知道的是如何从具有这样格式的 JSON 文件中做到这一点 -
{
"itemGuitar": {
"id": "itemGuitar",
"description": "Pete Townshend once played this guitar while his own axe was in the shop having bits of drumkit removed from it.",
"price": 5695.99,
"urls": [
"thewho",
"Pete_Townshend"
]
},
"itemShades": {
"id": "itemShades",
"description": "Yoko Ono's sunglasses. While perhaps not valued much by Beatles fans, this pair is rumored to have been licked by John Lennon.",
"price": 258.99,
"urls": [
"beatles",
"johnlennon",
"yoko-ono"
]
},
"itemCowbell": {
"id": "itemCowbell",
"description": "Remember the famous \"more cowbell\" skit from Saturday Night Live? Well, this is the actual cowbell.",
"price": 299.99,
"urls": [
"Saturday_Night_Live",
"More_cowbell"
]
},
"itemHat": {
"id": "itemHat",
"description": "Michael Jackson's hat as worn in the \"Bille Jean\" video. Not really rock memorabilia, but it smells better than Slash's tophat.",
"price": 1699.99,
"urls": [
"abc",
"def"
]
}
}
我需要帮助来获取使用 ajax 编辑的数据,使用 php 在 json 中修改它并使用 ajax 再次将数据加载到网页中。
这个json保存在一个文件中。
提前致谢!!
高拉夫纳加尔
到目前为止的 HTML 是——
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test HTML to save content editable on the go!!</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function sendData () {
var val = document.getElementById('editMe').innerHTML;
var cuenta = new Object();
cuenta.editMe = val;
$.ajax({
type: 'post'
, url: '/processDataFilePHP.php'
, dataType: 'json'
, data: { cuenta: editMe }
});
}
</script>
</head>
<body>
<h1 id="editMe" contenteditable="true">Hurray!!!</h1>
<button id="save" type="submit" onclick="sendData()">Save</button>
</body>
</html>
我还想知道如何交换保存在 json 中并由 php 返回的新测试。