2

I am using the below AJAX script to process some operation.

<script type="text/javascript">
function validLogin(){
  var uname=$('#uname').val();
  var password=$('#password').val();

  var dataString = 'uname='+ uname + '&password='+ password;
  $("#flash").show();
  $("#flash").fadeIn(400).html('<img src="http://www.91weblessons.com/demo/phpAjaxLoginValidation/image/loading.gif" />');
  $.ajax({
  type: "POST",
  url: "processed.php",
  data: dataString,
  cache: false,
  success: function(result){
           var result=trim(result);
           $("#flash").hide();
           if(result=='correct'){
                 window.location='update.php';
           }else{
                 $("#errorMessage").html(result);
           }
  }
  });
}

function trim(str){
 var str=str.replace(/^\s+|\s+$/,'');
 return str;
}
</script>

Here I need to redirect to a dynamic URL update.php?name=somename after success.

Please give any suggestions.

Fabien
  • 12,486
  • 9
  • 44
  • 62

2 Answers2

3

If you need to simulate a redirect, a better way is through window.location.replace(...). If its the same base protocol and origin, you could use window.location.replace(window.location.origin + '/update.php?name='+uname);

Refer to: How to redirect to another webpage in JavaScript/jQuery? for the difference between window.location.replace() and setting window.location.href

Community
  • 1
  • 1
0
window.location = '/update.php?name=' + userName;
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Glorious Kale
  • 1,273
  • 15
  • 25