简体   繁体   中英

How to refresh the page with updated data when click update button

function update(){

            var name= document.getElementById("TextBox").value;

$.ajax({
                            url: '....',
                            type: 'post',                               
                            data: {....//many data include// 'name' : name, ....},

                            success: function(data) {

                            var replacevalue=data.replace(/[\[\]']/g,'' );
                            alert(replacevalue);

                            var stringstatus=replacevalue.replace(/['"]+/g, '');
                            alert(stringstatus);                                

                            if(stringstatus == "success"){
                                alert ("Successfully Update ")                                                                          
                            }

                            else{
                                    alert("Failed!");
                                    return ;
                            }

                            returnToDisplayPage();


                        },                              

                            error: function(xhr, desc, err) {
                            console.log(xhr);
                            console.log("Details: " + desc + "\nError:" + err);
                            }
                });


    }

    function returnToDisplayPage(){
        var id = document.getElementById("TextBox").text;
        window.location = './DisplayPage.php?Name='+id;

    }

Please suggest me. How should I do to get the updated data when click update button and refresh or reload page ? In function returnToDisplayPage() methods. I got only the name of update data and other related fields data didn't get back.

Try something like this:

$.post('url', {params}, function(response){
    //Here you check if you got response from url
    // And then you can do whatever you like to do with received data
    if(response == 'ok'){
     //do your stuff
     //then
     window.location.reload();
   }
}

When we will get result in response then After 5 seconds page will be refresh..

success: function(data){
   if(data.success == true){ // if true (1)
      setTimeout(function(){// wait for 5 secs(2)
           location.reload(); // then reload the page.(3)
      }, 5000); 
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM