In Postman post request is working when i was sending the image but in external template is not working any solution

8 views
Skip to first unread message

yashwanth balanagu

unread,
Jul 15, 2020, 5:11:27 AM7/15/20
to Django users
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<script>

function postimage()
{
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange= function()
{
document.getElementById("image").innerHTML=xmlhttp.responseText;
}
posted={
fname:document.getElementById("name").value,
picture:document.getElementById("image1").value.replace('C:\\fakepath\\', "http://127.0.0.1:8000/media/photos/")

}

xmlhttp.open("POST","http://127.0.0.1:8000/api/v3/filedata/",true);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
console.log(posted);
xmlhttp.send(JSON.stringify(posted));
}

</script>

</head>
<body onload="get()">
<p id="sampledata1"> status data </p>
<p id="image"> sample image </p>
<input type="file" id="image1">
<br>
<br>
name:<input id="name" placeholder=" enter your name">
<br>
<br>
person:<select id="person" placeholder="enter your pg ">
</select>

<br>
<br>
<button onclick="change()"> Post </button>
<button onclick="postimage()"> post image </button>
</body>
</html>


Reply all
Reply to author
Forward
0 new messages