1

I'm trying to put a php variable within a js script that is in a result variable that will be processed with json but i don't get it to work. I know it has something to do with the "" and '' but i can't figure out what it is.

$result["html"] .= "<script type='text/javascript'>setTimeout(function () { window.location='.$config[\"BURL\"].'; }, 2500);</script>";

Edit: whoohoo i got the 15 points to upvote! Thanks u all!

5
  • Look at the output you get getting in View > Source. Determine what is wrong with it. Then worry about getting the PHP to output it correctly. Commented Dec 11, 2014 at 9:44
  • '".window.location='.$config[\"BURL\"].'" Commented Dec 11, 2014 at 9:45
  • i dont get any output Commented Dec 11, 2014 at 9:45
  • As a side point. If this is JSON, (by xhr?); wouldn't something like $result['BURL'] = "'" . $config["BURL"] . "'" be preferable? Do the processing of JSON $result client side and set timeout by JavScript instead of returning a whole document? Hard to say without knowing what you do, but only as a thought. Commented Dec 11, 2014 at 9:55
  • I've seen the way to code it like u suggest but i just return the value of $result to a DIV with jquery to another page because this one is called on the background and is only for processing. I'm not a king with English so if you want to know more pls feel free to chat since i find it very annoying to write everything here xD Commented Dec 11, 2014 at 10:03

1 Answer 1

4

You will have to concatenate strings using . and remove the escaping of the quotes for the index, like so:

$result["html"] .= "<script type='text/javascript'>setTimeout(function () { window.location='" . $config["BURL"] . "'; }, 2500);</script>";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.