开发者

Refresh a webpage with following action

开发者 https://www.devze.com 2023-03-22 14:10 出处:网络
I want to do a very simple thing with AJA开发者_StackOverflow社区X. Apologize if it sounds very simple.

I want to do a very simple thing with AJA开发者_StackOverflow社区X. Apologize if it sounds very simple.

If I add some new data to my database from my client side JS page (with AJAX call) with a save button, then I want make the newer data visible with that button click as well. For this, I assume I have following options -

  1. Refresh the page (which does not work for me since initially my table is hidden and refresh takes the page to its initial position. I also tried to refresh page and then added one action to make that table visible but unfortunately it just refreshed the page and did not perform the following action)
  2. Refreshing the part of the page (that certain div) which I have no idea how to do.

So my question is -

  1. Is it possible to refresh the page followed by other functions?
  2. How can I refresh a div using JS?

Either of the solutions would be fine for me. Thanks in advance.


To refresh a div, as far as I know you need a php page to get the info you want to be displayed in there then use ajax function to put that page in there.


You can have the server side code return the contents of the div to change after the data is saved.

Using jQuery it's very easy to change the content of a div after making an ajax call.

$.ajax({
    type: "POST",
    url: "/someurl",
    data: theDataToSendToTheServer,
    success: function(data){
        $('#theDivsId').html(data);
    }
});


JQuery's html() attribute will allow you to update a single div via Javascript. You can use JQuery's Post method to update the Server and/or retreive new data to refresh the div with.


Not using jQuery? It's still pretty easy.

document.getElementById('theIDofYourDiv').innerHTML = 'the new contents of your div, including <span>nested HTML tags</span> if you want, provided as a string';
0

精彩评论

暂无评论...
验证码 换一张
取 消