slk500
slk500

Reputation: 781

Pass values by AJAX to database

I'm creating a site LINK where user can "add" scenes to YouTube videos. Just providing scene name and start&pause time of the scene.

I created interface where user can do this. But right know I want to save user work to database. From my research I think I will use AJAX, or maybe you can recommend something else?

My main problem is what can I do with the code below? I'm creating buttons with title & start&pause time, but how I can pass that values to database? Maybe I have to create objects? Like every button will be a object with properties?

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() };
}

Upvotes: 1

Views: 564

Answers (1)

pratikpawar
pratikpawar

Reputation: 2098

You could make an ajax call and pass the values in JSON format to server. Just create a JS variable before ajax call

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

With in ajax call pass this data as

data : JSON.stringify(foo);

AJAX call would be

$.ajax({
url: url,
type: "POST", 
data: JSON.stringify(foo),
contentType: "application/json",
success:fuction(data){ //any logic to handle }
});

Upvotes: 1

Related Questions