0

I'm submitting a string and want to retrieve it back from the server. The issue seems to be that Flask's Request module isn't picking up the URL arguments - i.e. I get "HELLO" instead of the string variable.

As an aside, console.log(status) is undefined, and I'm not sure if that's related.

Here is the HTML...

<html>
<script type="text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<form>
    <input id = "entered_string" name = "string">
    <input type = "button" value = "submit" id = "submit_button">
</form>

<div id = "result">?</div>

<script>
$("#submit_button").bind("click", function(data, status){
    var string = $("#entered_string").val()
    console.log(string)
    console.log(data)
    console.log(status)
    $.get('/upper_case', function(string){
        console.log(string)
        $("#result").text(string.result)
        })
    })
</script>
</html>

and the server code...

@app.route('/', methods = ['GET', 'POST'])
def case_converter():
    return render_template("new.html")

@app.route('/upper_case')
def upper():
    print request.args
    string = request.args.get('string', "hello", type=str)
    print string
    return jsonify(result = string)

1 Answer 1

1

Don't know what you expect, that the callback of bind gets as arguments? There is only a single one event.

You have to send the string to the server:

$.get('/upper_case', {string:string}, function(string){
    console.log(string)
    $("#result").text(string.result)
    })
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, not sure why I missed this :-/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.