1

jquery ajax call

api_key=$('#acesskey').val();
    secret_key=$('#sacesskey').val();
    provider_name = $('#cname').val();
    $.ajax({
        type: "POST",
        data: {api_key:api_key,secret_key:secret_key,provider_name:provider_name},
        url: $SCRIPT_ROOT + "/login",
            contentType: "application/json; charset=utf-8",
            success: function(data) {
            alert(data.status);
            if(data.status == "True")
            {
                custom_ready();         
            }
        }
    });

python flask code

provider_name=request.args.get('provider_name')
api_key=request.args.get('api_key')
secret_key=request.args.get('secret_key')
print provider_name
print api_key
print secret_key

output
None
None
None

2 Answers 2

4

request.args contains the query string parameters (like bar in /foo?bar=42). You are doing a POST request and want to look in request.form.

See here: http://flask.pocoo.org/docs/quickstart/#the-request-object

Sign up to request clarification or add additional context in comments.

2 Comments

oky, so what i need to change in ajax call ? i changed python file according to instruction but still its not working.. status code 400 so i think i need to change ajax call also .. can you give me simple example ?
Post your whole view function that is supposed to handle this request. Run the dev server with debug=True. Post full tracebacks if there are any.
1

ajax call code

$.ajax({
    url: '/login',
    type: 'POST',
    data: {akey:akey,sakey:sakey,pname:pname},
    success: function(response){
        alert(response.status);
    }
});

HTML FORM

<form action="" method="POST">
</form>

Python code

akey = request.form['akey']
sakey = request.form['sakey']
pname = request.form['pname']

Comments

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.