0

I'm trying to post some json to the server from my single page app from the front End, Everything is working fine and i'm getting the data except the return statement where if I do a redirect to the /Contact I get Unexpected token < error. How do I go about this?

@app.route('/messageDump', methods=['POST'])
def messageDump():
  request_json     = request.get_json()
  print(request_json.get('firstName'))
  return redirect("/Contact", code=303)// gives error: Unexpected token < in JSON at position 0” 

  #return "helloWorld" //this is a comment: gives error Unexpected token h in JSON at position 0” 
Deke
  • 4,451
  • 4
  • 44
  • 65
  • What's json you are posting? Where are you getting error, messageDump or Contact handler? Did you try using `flask.redirect(flask.url_for('Contact'), code=307)`? You need to add a few more details into your question. – Boris Nov 15 '18 at 20:17
  • Hi I got this. in my front end I was doing `return "response.json();"` from my fetch api. because of which I was getting that error. My json data format looks like this : `{''firstName" : "a", "lastname" : "b", "message" : "bla"}` – Deke Nov 15 '18 at 20:22
  • You will need to provide the code in `/Contact`. Also, did you comment out your first return before doing `return "helloworld"`? If not, it will use the first `return`. – CodeLikeBeaker Nov 15 '18 at 21:57
  • Yes I return only one of them. i decided to return a 200 code from the server: `https://stackoverflow.com/questions/26079754/flask-how-to-return-a-success-status-code-for-ajax-call` – Deke Nov 16 '18 at 05:50

0 Answers0