From a php script I'm returning 3 values : all are transitioning over without any difficulty.
if(data.code == 600){
 var PNRRef = data.locator;
 var Lname = data.lname;
What I am trying to do is use these two var values in my redirect link and can't seem to figure it out :
window.location.href = '/US/en/local/res/MyReservation.php?PNRRef="PNRRef"&Lname="Lname"';
But it's not outputting correctly... Would anyone have a tip about how to integrate these ?
Thanks!
- 
 because you are not doing string concatenation, Those " quotes are doing nothing.epascarello– epascarello2018年03月08日 23:17:12 +00:00Commented Mar 8, 2018 at 23:17
- 
 take care of the variables encoding when replaced in the uri, check below, this saved me a lot of time ;)loretoparisi– loretoparisi2018年03月08日 23:24:48 +00:00Commented Mar 8, 2018 at 23:24
4 Answers 4
You need either to concatenate:
window.location.href = '/US/en/local/res/MyReservation.php?PNRRef=' + PNRRef + '&Lname=' + Lname;
or use Template literals (also called String interpolation)
window.location.href = `/US/en/local/res/MyReservation.php?PNRRef=${PNRRef}&Lname=${Lname}`;
Those variables need to be encoded (encodeURIComponent(...)) before to make any request like ajax.
Comments
window.location.href = `/US/en/local/res/MyReservation.php?PNRRef=${PNRRef}&Lname=${Lname}`
Comments
Probably template literals can be the solution for your issue.Instead of this:
window.location.href = '/US/en/local/res/MyReservation.php?PNRRef="PNRRef"&Lname="Lname"';
Use this:
window.location.href = `/US/en/local/res/MyReservation.php?PNRRef=${PNRRef}&Lname=${Lname}`;
Comments
I would go for a simpler solution (string concatenation) that always works
window.location.href = '/US/en/local/res/MyReservation.php?PNRRef='+encodeURIComponent(PNRRef)+'&Lname='+encodeURIComponent(Lname);
If you want to use a better URI encoding compliant to RFC3986 please use rfc3986EncodeURIComponent instead of encodeURIComponent:
function rfc3986EncodeURIComponent (str) { 
 return encodeURIComponent(str).replace(/[!'()*]/g, escape); 
}