-2
function theFinale()
{ document.getElementById("pop2").style.display = 'none';
       document.getElementById("myPopup").style.display = 'none';
       document.getElementById("pop3").style.display = 'none';


        document.getElementById("pop4").style.display = 'block';
         document.getElementById('pop4').style.position = "absolute";
         document.getElementById('pop4').style.top = '250px';
        document.getElementById('pop4').style.left = '250px';
        setTimeout(function(){
        document.getElementById('pop4').className = 'waa';
        }, 2500);
    window.line=document.getElementById('answer').value;

                {
                  $.ajax({
            type: 'POST',
            url: 'qwe.php',
            data: {z: line},
            success: function(data) {

                $("q").text(data);

            }
        });
            document.getElementById('answer').reset();
                }
                 window.location.href=window.location.href;
}

i want to refresh after this function is executed. all the form values that i take in the html form should also be reset.

Rahul
  • 15
  • 1
  • 1
  • 5

2 Answers2

3

$.ajax() returns results asynchronously. Move window.location.href=window.location.href to success function of $.ajax(). Remove two syntax errors { before $.ajax() call and } following document.getElementById('answer').reset();. Provide an identifier for setTimeout, and call clearTimeout() at success

Outside of theFinale function

var timeout = null;

timeout = setTimeout(function(){
    document.getElementById('pop4').className = 'waa';
}, 2500);

success: function(data) {
            clearTimeout(timeout);
            window.location.href=window.location.href;

         }
guest271314
  • 1
  • 15
  • 104
  • 177
0
success: function(data) {
           $("q").text(data);
           location.reload()
        }

Did you try this?

nikjohn
  • 20,026
  • 14
  • 50
  • 86