The idea is I'm trying to send a set or list to the backend. I'm using JavaScript on the front end and sending the data via fetch. For the backend I'm using Flask.
const walls1 = new Set()
// Submit Button
document.addEventListener('DOMContentLoaded', function(){
document.querySelector('#search_button').onclick = function(){
// Send a GET request to the URL
fetch('http://127.0.0.1:5000/search',{
method:"POST",
body: JSON.stringify(walls1),
headers: {
"Content-Type": "application/json"
}
})
// Put response into json form
.then(response => response.json())
.then(data => {
console.log(data)
console.log(walls)
})
};
});
All I want to do is print this set in my backend for now, but can't seem do this successfully.
@app.route("/search", methods=["POST"])
def search():
print(request.json) **// prints {}, but the set does have items, so this isn't right**
print(request.data) **// b'{}'**
info = {"success": True}
return jsonify(info)
Update: It looks like the set I am sending from the front end to the backend is empty? But I don't understand why because console.log(walls) prints a non empty set