I don’t what is causing this to make error.Maybe I think it’s a small thing to be changed but I am not able to find this.Please help me through this.
What i want to dis send the file address to server and format it for something,that code I haven’t added but the address is not being formatted.Help will be appreciated
<div class="container">
<form class="form-signin" method="post" role="form">
<h2 class="form-signin-heading">Please Sign Up </h2>
<div>
<input type="text" name="address" placeholder="Drivers" class="form-control col-3 mr-4">
</div>
<div>
<button class="btn btn-outline-light d-inline-block" style="width: 150px;float: left;" id="upload">Upload</button>
</div>
</form>
</div>
$(function() {
console.log("working")
$('#upload').click(function() {
console.log("inside is working")
$.ajax({
url: '/signUpUser',
data: $('form').serialize(),
type: 'POST',
success: function(response) {
console.log(response)
console.log(data.address);
},
error: function(error) {
console.log(error);
}
});
});
});
@app.route('/')
def index():
return render_template('index.html')
@app.route('/signUpUser', methods=['GET','POST'])
def signUpUser():
if request.method=='POST':
address=request.form['address']
return jsonify({'address':address});
2
Answers
Method not allowed means the route has not been set up for
GET
or most likelyPOST
, this error is coming from your API meaning you haven’t specified on your route what method it should be so it fails. I’m pretty sure it defaults toGET
but if you’re callingPOST
then it will complain at you with this error. Without seeing your api code that’s about as much help as we can give.The problem is because you’ve not prevented the standard form submission. This means that you’re sending a standard form request to the current page, which is not configured to receive POST requests, hence the error you see.
To fix the problem attach a
submit
event handler to theform
instead and callpreventDefault()
on the event which is provided as an argument to the handler function;