javascript - JQuery attempt to change window.location incorrectly truncating query parameters -
i'm experimenting jquery fun , i've run bit of brick wall. i'm attempting write login page , thought have form on jsp user enter login id , password , click submit button. gets caught jquery method makes ajax call back-end. "success" method should set window object's location new url indicated value returned ajax call. fyi: i'm back-end guy , have portion covered. problem although call back-end , data require. attempt set new window location url contains single query parameter (to allow app know user is), works base url no query parameters (though there '?' on end of base url)
here's jquery code:
</script> $(document).ready(function(){ submit( function() { var id = $("#login_id").val(); var pwd = $("#password").val(); var uri = "`http://localhost:8080/sw_server/rest/admin/login`"; $.ajax({ async: false, url: uri, type: 'get', datatype: "json", success: function(data) { var session = data.session; newloc = data.redirect+"?"+data.session // prevent form's default submission. preventdefault(); // prevent event bubbling dom tree, prohibiting delegation event.stoppropagation(); window.location.replace(encodeuricomponent(newloc)); }, error: function(jqhhr, textstatus, errorthrown) { alert("textstatus: "+textstatus+"\nerror: "+errorthrown); // prevent form's default submission. event.preventdefault(); // prevent event bubbling dom tree, prohibiting delegation event.stoppropagation(); } }); }); </script>
when execute this, end returns data.redirect=http://localhost:8080/test.jsp
, data.session=session_id=3, see in alert (hooray me), when window.location.replace(newloc) called goes http://localhost:8080/test.jsp?
no query parameter. i've been banging head day. can query param correctly picked new page?
regards,
tim
try assign value location
instead
window.location = data.redirect;
Comments
Post a Comment