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

88
Views
Get rendered template in return from AJAX POST request and refresh the page (not working)

I am trying to send a post request using ajax and refresh my page with the rendered template returned from backend, It refreshes the page but it is not working like it is supposed to, The javascript is broken.

Is there any other way to do this?

Please find the simplified version of the code below:

JAVASCRIPT

$.ajax({
    url: "/post_data",
    type: 'POST',
    contentType: false,
    data: myForm,
    success: function(data){
        console.log("data posted")
        //rendered tempalte returned used to overwrite document
        document.write(data)
    }
    })

PYTHON

app.route("/")
def index(dataName=""):

    if dataName:
        #perform some changes in myTest.html
        print("dataname: ", dataName)
        
    return render_template("myTest.html")    


@app.route('/post_data',methods=["GET","POST"])
def post_data():
    myData = request.form["myDataName"]
    
    #return rendered template returned from index function
    return index(myData)
about 4 years ago · Juan Pablo Isaza
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!