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

140
Views
content gets hidden while using ajax

I am using ajax for fetching records using following code.

<html>
<head>
<script>
$(function() {
    $('.go-btn').on('click', function() {
        var selected = $('#my-dropdown option:selected');
            $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "boxplot.html",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $("#responsecontainer").html(response); 
            //alert(response);
        }

    });
        //alert(selected.val()); 
    });
});
</script>
</head>
<body>

some text
<button class="go-btn" type="submit">Go</button> 
<div id="responsecontainer">
<br><hr><br>
<h2>PCA Plot Distribution:</h2><br>
</body>
</html>

In the above code, content page gets loaded on clicking button (at ) but anything after this gets disappeared. How can i fix this issue?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Because you are setting your response to whole div. Fix your html such that

<div id="responsecontainer"></div> 
<div>
<br><hr><br>
<h2>PCA Plot Distribution:</h2><br>
</div>

So you are settings your response to responsecontainer and rest remains same.

about 4 years ago · Santiago Trujillo Report

0

You haven't closed your div in the HTML in the bottom

about 4 years ago · Santiago Trujillo Report

0

You just have to close that #responsecontainer div.

var response = "my Response";
$("#goButton").on("click", function(){
  $("#responsecontainer").html(response);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>

some text
<button class="go-btn" type="submit" id="goButton">Go</button> 
<div id="responsecontainer"></div>
<br><hr><br>
<h2>PCA Plot Distribution:</h2><br>
</body>
</html>

about 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!