0

When I do this:

onClick = "return generateClient('<?php echo json_encode($_POST)?>');"

I am getting this error on the google chrome console.

Uncaught SyntaxError: Unexpected token ILLEGAL

But when I do this from php:

print_r(json_encode($_POST));

I get:

{"lang-select":"C++","question-id":"1","method-name":"Rishi","param-count":"1","lib-path":"c:\\h\\b.out","return-select":"unsigned int","sample-count":"1","class-name":"m"}

What can be the fault in this?

2
  • fixing syntax errors is part of the debugging process. That's something you have to do yourself. This isn't a free debugger service Commented Jul 24, 2013 at 11:22
  • Have a look at the generated source or the DOM inspector. Is it how you expect it to be? Commented Jul 24, 2013 at 11:24

1 Answer 1

2

Your data contains " characters.

Your attribute values are delimited by " characters.

The first " in the data will end the attribute value.

A validator would have picked this up for you.

Run your data through htmlspecialchars to encode the quote marks.

Sign up to request clarification or add additional context in comments.

Comments

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.