Jump to content

Javascript command inserted by php


Arbu
 Share

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:

loadfile('{
	...
	...
}');  

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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...