Reputation: 802
My django views
def contact_otp(request):
if request.method=="POST":
data = {
"data-token":f"{otp.token}"
}
#
return JsonResponse(data)
.then((response) => response.json())
.then((data) => {
console.log(data)
const newVarPass = document.createElement("input")
newVarPass.setAttribute('id','varPassID')
newVarPass.setAttribute('value',`${data}`)
newVarPass.value=`${data}`
newVarPass.style.display="none"
document.body.appendChild(newVarPass)
alert("Check your Email We have send you the otp")
console.log(data)
})
x = document.getElementById("varPassID")
console.log(x)
console.log("Lets check")
How to get the values of the json keypair i want to have which is present in the json data i am always getting object object in the value now
updated console.log(data)
Upvotes: 0
Views: 70
Reputation: 1756
document.getElementById("varPassID").innerText = data.data-token
Reference: https://www.w3schools.com/jsref/prop_node_innertext.asp
Upvotes: 1