Jump to content

problem with php code inside a javascript


Cole001

Recommended Posts

Hello,

 

I have a php code within a javascript. The javascript gets invoked on button click. The php code withing javascript never gets executed. I don't face the same problem in other browsers. Any help is much appreciated!

 

Regards,

Cole

Php is a server side scripting language. It is executed on the web server when the page is requested. You only get the output that php sends to the browser. Javascript is a client (browser) side scripting language. It is executed after the page is received in the browser. So, there is actually nothing such as php code inside of javascript.

 

In any case, we cannot help you with any of your code unless you post all the code that reproduces the symptom.

You can however trick things by writing the JS lines as well to a variable.

So say for example you have this that doesn't work.

<script type="text/javascript">
url: '{<?php echo $rowpath; ?>}',
</script>

 

Try this

$path="url: '{$rowpath}',\r";
<script type="text/javascript">
<?php if(isset($path)){echo $path;} ?>
</script>

At least I've been able to get things to work like this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.