I got the following problem. I created a python script a while ago that allowed me to download a youtube video. Then i thought it would be cool if I created my own firefox addon working with the script to download the videos directry from the browser. So I started out and watched some tutorials and realized i could only work with js to create an addon. The I looked for a solution to send the data from my Javascript to my python script and then download the video. I then started with an AJAX Post method which I found out would be the best for my case but it just doesnt do anything. I tried multiple things to get it to work but I dont get anything returned. Here is my code(JavaScript):
console.log("Loaded Successfully!");
function postData(jsdata) {
$.ajax({
type: "POST",
url: "/receivedata",
data: { "myData": jsdata },
success: callbackFunc
});
}
function callbackFunc(response) {
console.log(response);
}
postData('Hello')
console.log("Sent data successfully");
Here is the python script:
import flask
import json
from flask import request
app = flask.Flask(__name__)
@app.route('/receivedata/', methods=["GET", "POST"])
def receivedata_():
if request.method == "POST":
print(request.form["myData"])
Message = {"Message":"Hello World"}
return Message
if __name__ == "__test__":
app.run(debug=True)
And if you need it heres my manifest.json:
{
"manifest_version": 2,
"name": "Test",
"version": "1.0",
"description": "Test Addon!",
"content_scripts": [
{
"matches": ["*://*.youtube.com/watch?*"],
"js": ["test.js"]
}
],
"permissions": [
"*://youtube.com/*"
]
}
http://localhostto the url or the extension will send that request to the site you're visiting I guess. Also, you're using jQuery in your extension script. a) did you include it? b) you can use fetch() instead