DrB*_*oon 6 javascript php jquery json asp-classic
我想通过说我知道我在做什么并不理想来作为序言.有了这个:
我需要通过javascript更新JSON文件中的数据.这是目前的JSON文件:
{
"nextid" : 3,
"ingredients" : [
{
"id": 1,
"name": "onion",
"kilojoules": 180,
"quantity": 1,
"measurement": "whole",
"nutrition": [
{"value": "Fat Total", "quantity": 110},
{"value": "Saturated Fat", "quantity": 46},
{"value": "Sodium", "quantity": 4},
{"value": "Carbohydrates Total", "quantity": 10000},
{"value": "Sugar", "quantity": 5000},
{"value": "Fibre", "quantity": 2000},
{"value": "Proten", "quantity": 1000}
]},
{
"id" : 2,
"name": "carrot",
"kilojoules": 56,
"quantity": 1,
"measurement": "whole",
"nutrition": [
{"value": "Fat Total", "quantity": 66},
{"value": "Saturated Fat", "quantity": 11},
{"value": "Sodium", "quantity": 26},
{"value": "Carbohydrates Total", "quantity": 3000},
{"value": "Sugar", "quantity": 2000},
{"value": "Fibre", "quantity": 1000},
{"value": "Proten", "quantity": 279}
]}
]
}
Run Code Online (Sandbox Code Playgroud)
现在让我们说我想编辑胡萝卜对象.我在我的html页面上构建了一个更新的胡萝卜对象,并将其作为javascript中的对象.我需要做些什么才能使用我的编辑来更新源json?
就像我之前说过的,我知道这不太理想.我应该使用一个数据库来存储和操作数据,但我现在已经把我的床铺了起来,我必须让它工作,不管它有多大可能会让你感到畏缩.
研究告诉我,我将需要在服务器端使用PHP或ASP来收集javascript传递给它的参数,但我不知道从哪里开始.
我在visual studio 2012工作,项目的参数禁止我使用插件.NuGet代码库是的,但没有插件.在此基础上,我认为这意味着我不能使用PHP.我的想法是否正确?
注意:是的,它用于分配,但是更改json文件超出了要求的范围.能够动态处理json数据对于项目来说已经足够了,我真的很想能够放回一些.
提前致谢
编辑:可能也应该分享这个.这是打开json文件的javascript.打开的结果存储在名为ingJson的脚本范围变量中.
function downloadIngredients() {
$(document).ready(function () {
$.getJSON("/data/ingredientsInfo.js", function (result) {
try
{
ingJson = result;
ingredients = result.ingredients;
ingredients.sort(orderByNameAscending);
buildListBox(ingredients);
}
catch (err) {
alert(err.message);
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4850 次 |
| 最近记录: |