sarangkkl
sarangkkl

Reputation: 802

how to access the Json Responce dict value in the Html script

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")

enter image description here

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)

enter image description here

Upvotes: 0

Views: 70

Answers (1)

Chandragupta Borkotoky
Chandragupta Borkotoky

Reputation: 1756

document.getElementById("varPassID").innerText = data.data-token

Reference: https://www.w3schools.com/jsref/prop_node_innertext.asp

Upvotes: 1

Related Questions