I am currently trying to request Data with Java Script from my API but it doesn`t work. Everytime i POST i get the error, that "TypeError: 'NoneType' object is not subscriptable" in FLASK. Code of my API:
#http://127.0.0.1:5000/fnd
@app.route('/fnd', methods=['POST'])
def fnd():
content = request.json
return jsonify(content['Text'])
For the Post I am using JQuery AJAX Requests
$(function ()
{
var output = $('#output');
$('#checkonfake').on('click',function(){
var texttocheck = $('#texttocheck').val();
var datad = {"Text": texttocheck}
console.log(datad);
if(texttocheck != ""){
$.ajax(
{
dataType: "json",
type: 'POST',
data:
{
datad
},
url: 'http://127.0.0.1:5000/fnd',
success: function (result)
{
console.log(result);
},
error: function ()
{
console.log("error");
}
});
}
})
});
I have like a Input Box and a button and as soon as i press the button the request should be sent off.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>405 Method Not Allowed</title> <h1>Method Not Allowed</h1> <p>The method is not allowed for the requested URL.</p>contentis emty. The reason why you getThe method is not allowed for the requested URLis that the method fordef fnd()is different from what you are using with POSTMAN.