Reputation: 825
Hello I am trying to refresh my page using ajax. Here is the code:
<script>
function reld_email_posts() {
$("#loading").fadeIn();
$.ajax({
type: "POST",
url: "xpostings.php",
data: dataString,
success: function(){
$("#loading").fadeOut();
}
}
</script>
<input type="button" name="" id="" onclick="reld_email_posts()" value="Refresh Records" />
Its kind of geared towards the right direction but its needs more. Does anybody know how I can refresh my page using ajax?
Upvotes: 0
Views: 494
Reputation: 1408
Assuming that your ajax call is returning HTML, I would do something similar to the following. Keep in mind it's not going to refresh your entire page, but will re-populate the contents of the "loading" HTML element. That being said you will need an HTML element such as a div to populate with the response data. Just make sure that the loading div holds all the content on your page and you will get the feel of a full page refresh without actually refreshing the page.
<div id="loading"></div>
function reld_email_posts() {
$("#loading").fadeOut();
$.ajax({
type: "POST",
url: "xpostings.php",
data: dataString,
success: function(data){
$("#loading").empty().append(data);
$("#loading").fadeIn();
}
}
Upvotes: 0
Reputation: 58531
Your success function does not do anything with the data it receives from the url, but it just fades out the loading element. You need to accept, and handle the returned data in the success function...
success: function(data){
// do something with data here...
// eg... $('#someDiv').html(data)
$("#loading").fadeOut();
}
If you want to refresh the whole page: Redirect from an HTML page
Upvotes: 1