Skip to content

Instantly share code, notes, and snippets.

@Shervin1995
Created June 14, 2020 06:05
Show Gist options
  • Save Shervin1995/f0676f021022a977ed0f486c9d7a2d39 to your computer and use it in GitHub Desktop.
Save Shervin1995/f0676f021022a977ed0f486c9d7a2d39 to your computer and use it in GitHub Desktop.
2020-june-14 | rest api - post method
let srial = `folderID=${folderID}&folderName=${folderName}`
let xhr = new XMLHttpRequest()
xhr.open('POST','http://localhost:8080/api/folder/'+courseName,true)
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xhr.send(srial)
-------------------------------------------------------------------
{/*
Means1 >> I didnt use e.preventDefault() !
(
why? becuase see added folder WITHOUT refresh whole browser!
cant add it via innerHTML?
yes but cant add video to new folder!
)
Means2 >> may use location.reload() !
Means3 >> I could refreshing by Ajax !
because it need state management and I want to study it later!!
*/}
-------------------------------------------------------------------
function submitAddFolder() {
var form = $("#folderform")
let send = form.serialize()
$.ajax({
type: "POST",
url: 'http://localhost:8080/api/folder',
data: send
})
let x = form.serializeArray()
let x3 = document.querySelector('.folder-ul')
let x4 = x3.innerHTML
x3.innerHTML = x4 + `<li class='oneFolder'>
<a class='folder' style='margin-left:20px;color:darkgreen'>
${x[1].value}</a></li>`
let x1 = document.querySelector('.input1')
let x2 = document.querySelector('.input2')
x1.value=''
x2.value=''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment