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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.