Last active
August 29, 2015 14:07
-
-
Save ErikPeterson/46670c64cdab9f550fdc to your computer and use it in GitHub Desktop.
example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The body of the html | |
<body> | |
<ul id="my-items"> | |
</ul> | |
<form id="myform"> | |
<input name="myvalue" type="text"></input> | |
<input type="submit" id="thebutton"></input> | |
</form> | |
.... | |
//Javascript to get the data from the server | |
function getData(){ | |
var req = new XMLHttpRequest(); | |
... | |
//set up your request to get data from the server and execute it | |
//assign the set data function to the request's onload event | |
req.onload = setData; | |
} | |
//this function could be reused for refreshing the page from the server | |
function setData(){ | |
//parse the data that comes back | |
//select your list | |
//delete the old data | |
//insert the new data | |
} | |
var submitbutton = document.getElementById("thebutton"); | |
submitbutton.onclick = submitForm; | |
function submitFrom(e){ | |
//e is the event for clicking the button | |
e.preventDefault() | |
//this prevents the form from actually submitting | |
var text = document.getElementById("myvalue").value; | |
//this gets the value that the user has put in the form field | |
sendData(text); | |
//this calls a function to send the data to the server with the text from teh form as its | |
} | |
function sendData(text){ | |
//send your data to the server with request | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment