1

I'm working in a framework where not all the pages are the same relative path from the asset directories, so they often use a WWW variable to get the correct path to css, php, js files etc.

I'm setting up a form that submits via ajax, and for the url path to work, it will have to be an absolute path, but based on a variable ideally for maintainability.

Since that WWW variable is already set up in the php, I was thinking about including a php page with <script> tags and that way I can use the same variable..

Is that considered really kludgy? or is there another way to do it? Ideally I want to have all the config just in one file to make it more easily portability, which is why I don't just have a js file with the path. So if there's some way to autogenerate it or something...

1
  • Seems fine to me too. That's the way I work. Commented Jun 17, 2011 at 18:25

2 Answers 2

2

I usually just render that kind of stuff on page instead of incurring a separate request just to get a variable.

For example:

<script type="text/javascript">var www_var = '<?php echo $www_var; ?>'</script>
Sign up to request clarification or add additional context in comments.

1 Comment

makes sense! what I ended up doing on another recommendation is including a meta tag with the php variable echoed out in it. Your way is a little more direct.
0

I assume there's some complication in using a base-url relative path like /path/to/foo/? I personally don't like to mix programming languages like this. In other words, I consider it not to be proper to do this.

1 Comment

yeah... the way the cms is built the homepage loads from the root dir and the others from subfolders.

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.