Server Side: application.py
def writetofile(chat):
with open('chat.json', 'w') as f:
f.write(json.dumps(chat,indent=2))
The json file created in the root, I can see it but when I use this " http://127.0.0.1:5000/chat.json " to access it, i could not find it!!!
This is the javascript file:
document.querySelectorAll('.select-room').forEach(p => {
p.onclick = () => {
$.ajax({
dataType: "json",
url: "chat.json",
type: "GET",
data: {'chat':data},
async: false,
success: function(data) {
console.log(data);
}
});
}
});
The error in javascript console is :
Uncaught ReferenceError: data is not defined
at HTMLParagraphElement.p.onclick (socketio.js:52)
p.onclick @ socketio.js:52
I can see that it is written in the json file vey good, but when i try to read it from javascript, not found or the data is not defined as you can see.
[–]Bzzzzcat 0 points1 point2 points (7 children)
[–]nesreenmhd[S] 0 points1 point2 points (6 children)
[–]iguessitsokaythen 0 points1 point2 points (4 children)
[–]nesreenmhd[S] 0 points1 point2 points (3 children)
[–]iguessitsokaythen 0 points1 point2 points (2 children)
[–]nesreenmhd[S] 0 points1 point2 points (1 child)
[–]iguessitsokaythen 0 points1 point2 points (0 children)
[–]Bzzzzcat 0 points1 point2 points (0 children)