This may be a simple thing to do but I cannot figure it out for some reason. On the SAME webpage, I'd like to send the clicked word in HTML to the server, and have the server send it back and alert the word.
On the flask .py file, I have this (it used to look different and more reasonable but now idk what I'm even doing):
@app.route('/render/', methods=['GET'])
def render():
if request.method == "GET":
jsondata = request.get_json()
query_string = request.query_string
#data = json.loads(jsondata)
print(query_string)
if query_string != None:
print(query_string)
return render_template('read.html', yup=jsondata)
On the JavaScript/HTML side, the client sends the hovered-on word (and I know that the server sees it as, for example, "GET /render/?%22whats%22 HTTP/1.1" 400 -, but it's not quite retrieving it or sending it back.
$("#readMain").delegate("span", "mouseenter", function() {
var toSend = $(this).text();
$.ajax({
url: window.location.href,
type: 'GET',
data: JSON.stringify(toSend),
contentType: 'application/json; charset=UTF-8',
});
$("#readMain").delegate("span", "click", function() {
var jsonStr = JSON.stringify('{{yup}}');
alert(jsonStr);});
What to do? Please help!
POSTrequest?