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

604
Views
Change content in iframe without reloading page with AJAX and Jquery

In my webpage there is an iframe which shows some data. When user clicks on a button on the parent page, the content in iframe should be changed. What I did was sending a get request with specifiying the content to be changed using AJAX. Then the server sends back an html page with content requested. Here is my code,

html:

<button id="new-folder" class="control">Folder</button>


<div id="iframe-div">
    <iframe src="/tree" name="main_iframe">
    </iframe>
<div>

javascript(Jquery and AJAX):

$(document).ready(function(){

    $("#new-folder").click(function(e){
        $.get("/tree", {control: "new-folder"}, function(data){
           $("#main-iframe").location.reload();
        });
    });

});

What this does is when user click on button(#new-folder) a post request is sent specifying folder name. It is working great. Also response is getting back successfully. Now I need to do is show the response data on the iframe without reloading. Response is an html page. But the response is not showing in iframe unless realoding it.

I tried

$.get("/tree", {control: "new-button"}, function(data){
    $("#main-iframe").contents().find("html").html(data);
});

and many more similar methods. But non of them are working. Even the reload() method is not working. My main target is to update the content iframe without reloading. response is a html page. So what do I need to do. I'm using Jquery and AJAX.

Edit:

The above post which was suggested doesn't answer my question. Because I'm looking for a way to change/update the content in iframe without reloading it. But the suggested answer is about reloading iframe. I tried to reload the iframe as a temporary solution. That's not what I'm expecting. Also the tried solutions aren't working in my code.

over 4 years ago · Santiago Trujillo
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!