通过AJAX将值传递到数据库
Pass values by AJAX to database
我正在创建一个网站链接,用户可以在其中向YouTube视频"添加"场景。只需提供场景名称和开始&场景的暂停时间。
我创建了用户可以执行此操作的界面。但我想把用户的工作保存到数据库中。根据我的研究,我想我会使用AJAX,或者你可以推荐其他东西吗?
我的主要问题是我能用下面的代码做什么?我正在创建标题为&启动&暂停时间,但如何将这些值传递到数据库?也许我必须创建对象?就像每个按钮都将是一个具有属性的对象一样?
function createButtons(start, stop, scene_name){
counter++;
var button = document.createElement("BUTTON");
var text = document.createTextNode(scene_name);
button.appendChild(text);
var button_del = document.createElement("BUTTON");
button.type = "button";
button.id = "BUTTON_scene";
button.name = "BUTTON_scene_"+counter;
button_del.type = "button";
button_del.id = "BUTTON_delete";
button_del.name = "BUTTON_del_"+counter;
var added_scene = document.getElementById("added_scene")
document.getElementById("added_scene").appendChild(button);
document.getElementById("added_scene").appendChild(button_del);
var test = document.getElementsByName("BUTTON_scene_"+counter)[0];
var test2 = document.getElementsByName("BUTTON_del_"+counter)[0];
button.onclick = function () {playerInstance.seekToPause(start,stop)};
button_del.onclick = function () { test.remove(); test2.remove() };
}
您可以进行ajax调用,并将JSON格式的值传递给服务器。只需在ajax调用之前创建一个JS变量
var foo = {foundation: "Mozilla", model: "box", week: 45 } //in your case you could give change property names foundation/model/week and set values which needs to be sent to server
使用ajax调用将此数据作为传递
data : JSON.stringify(foo);
AJAX调用将是
$.ajax({
url: url,
type: "POST",
data: JSON.stringify(foo),
contentType: "application/json",
success:fuction(data){ //any logic to handle }
});
相关文章:
- 如何通过php页面将数据库值检索到jquery自动完成框中
- 如何将输入范围的值传递给JS中的变量
- 如何将值传递给wicket中的javascript函数
- 将值传递给jquery创建的输入字段
- 如何在javascript谷歌地图中获取数据库值
- 需要将select标记选项值传递给ajax函数
- 使用Ajax将PHP值传递给javascript
- 将javascript值传递给PHP
- 将javascript值传递给php是正确的方法
- 将不属于表单的HTML页面中的值传递给php页面
- 按钮,用于更改Rails中的数据库值
- Angular,将文本框的动态值传给控制器
- 在key up函数上将文本框值传递给javascript
- 可以't使用ajax调用将值传递给Web服务
- 如何在同一页面上使用windows.location.href将js值传递给php时停止刷新页面
- 多个单选按钮,需要将选定的值传递给javascript
- 将 MSSQL 表值传递给 javascript
- 使用Javascript和Json将选择选项值传递给PHP并从数据库中检索数据
- PHP:如何将数据库值传递给javascript/jquery函数
- 将相同名称的文本框的值传递给jquery,然后传递给php页面,以便将值存储到数据库中