Jump to content

Javascript command inserted by php

Recommended Posts

I'm using this code

 <?php if (isset($_POST["json"])) : ?>
loadfile('<?php echo $_POST["json"] ?>');  
 <?php endif; ?>

to insert a command into my scrjavascript script and it appears like this:


But I get a message for the loadfile line "Uncaught SyntaxError: Invalid or unexpected token". I can't see anything wrong. Why am I getting this error?

Link to post
Share on other sites
5 hours ago, Ingolme said:

It is probably that there is a quotation mark in the JSON contents.

Yes, there are loads.

It seems that if I remove the single quotes around the php command the error goes away. I don't actually understand why they were there in the first place.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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