Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Ajax POST Request to Flask Application

I am trying to create a POST request from ajax using input type button. But the request is not sending

Need to send two separate request from each like below

html

            <input type="button" class="far fa-check-circle" name="hvalid" id="hvalid">
            <input type="button" class="fas fa-times-circle" name="hinvalid" id="hinvalid">

ajax

$(function(){
    $('input').click(function(){
        var hvalid = $('#hvalid').val();
        var hinvalid = $('#hinvalid').val();
        $.ajax({
            url: '/pending_val',
            data : {'hvalid':hvalid,
                     'hinvalid':hinvalid},
            type: 'POST',
            success: function(response){
                console.log(response);
            },
            error: function(error){
                console.log(error);
            }
        });
    });
});

Flask Route

@data_sources_api.route('/pending_val', methods=["GET", "POST"])
def pending_val():
        if request.method=='POST':
            print(request.form)

How hvalid and hinvalid request can be send separately

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

html

 <input type="button" class="far fa-check-circle" name="hButton" id="hvalid">
  <input type="button" class="fas fa-times-circle" name="hButton" id="hinvalid">

ajax

$(function(){
$('input[name="hButton"]').click(function(){
    $.ajax({
        url: '/pending_val',
        data : {'hvalidity': this.id },
        type: 'POST',
        success: function(response){
            console.log(response);
        },
        error: function(error){
            console.log(error);
        }
    });
});
});

Flask

data_sources_api.route('/pending_val',methods=["GET", "POST"])
def pending_val():
    if request.method=='POST':
        print(request.form.get('hvalidity'))
    return json.dumps({'success':True}), 200, {'ContentType':'application/json'} 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!