Insert a property from a JavaScript object into a string -


why js window.location not accept variable assigned json, hava checked json, , json exist console.log(myjsoncallback)

 object { status=1,  action="update",  id=90} 

the code this,

if(response.action === "update"){     var id = response.id;window.location.href=        "/index.php?r=kasir%2ftransaction%2fview&id=id"} 

in browser, little funny coz gives me :

http://10.60.36.79/index.php?r=kasir%2ftransaction%2fview&id=id 

please advice

update

my original code :

. 'if(response.action === "update"){'    . ' var id = response.id;'    . 'window.location.href= "' . url::toroute(['view']) . '&id=${id}"'   . '}' 

see, use dot(.) cos code string on php

please advice

if expected work interpolate variable, this:

/index.php?r=kasir%2ftransaction%2fview&90=90 

but string not contain variables. try instead:

if(response.action === "update") {   var id = response.id;   window.location.href = "/index.php?r=kasir%2ftransaction%2fview&id=" + id; } 

or if using es6, can use template literals

window.location.href = `/index.php?r=kasir%2ftransaction%2fview&id=${id}`; 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -