I'm opening a popup window after an click on my main page using jquery. The pop up window has a button that should call a function on click. Unfortunately, the opened window shows an error in the console. I should note that if I attach the window.close() function to my button, the console still shows the error but the button does close the window so perhaps I have multiple problems in my code.
JS:
function jb_log_js(jb) {
console.log("jb_log_js lancée");
$.ajax({type: 'POST',
url: "http://127.0.0.1:5000/jb_log",
data: JSON.stringify(jb),
success:function(data){console.log("jb_log_js callback");
var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top="+(screen.height-400)+",left="+(screen.width-840));
win.document.body.innerHTML = data;},
contentType: 'application/json',
dataType : 'json',
}
);
console.log("jb_log_js finie");
}
Python Flask:
@app.route('/jb_log',methods=['GET','POST'])
def jb_log_py():
print("jb_log_py lancée")
if request.method == 'POST':
print("entrée if")
print(request.is_json)
print(request.get_json(force=True))
liste_jb= request.get_json(force=True)
print(liste_jb)
template = render_template('jb_log.html',title="connexion",liste_jb = liste_jb)
return json.dumps(template)
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="{{ url_for('static', filename='jquery-3.6.0.js')}}"></script>
<script src="{{ url_for('static', filename='script.js')}}"></script>
</head>
<body>
<div>
<form>
{% for jb in liste_jb %}
<label for="identifiant">Identifiant pour {{jb}}:</label><br>
<input type="text" id="identifiant" name="{{jb}}"><br>
<label for="mdp">Mot de passe pour {{jb}}:</label><br>
<input type="text" id="mdp" name = {{jb}}><br>
{% endfor %}
<input type="button" value="Valider" onclick="lancement_scraping()">
</form>
</div>
</body>