0

How is the best way to send string from javascript to php with html tags inside? I'm trying, but all html tags disappear.

var ajaxData = '<div>some <b>text</b></div>';

jQuery.ajax({
            url: url,
            type: 'POST',
            dataType: 'json',
            data: ajaxData,
});

but in my php code var_dump($input); shows string like that: 'some text' instead

'<div>some <b>text</b></div>'

even this doesn't work

htmlspecialchars(urldecode($input));
4
  • Please explain in brief what you want to do Commented Aug 14, 2014 at 11:57
  • replace data: ajaxData with something like this data: {'ad': ajaxData} Commented Aug 14, 2014 at 11:58
  • You shouldn't be using urldecode on $input either if it comes from one of the request superglobals. Commented Aug 14, 2014 at 11:58
  • Have you used json.stringify Commented Aug 14, 2014 at 12:07

2 Answers 2

1

did you tried to view source? var_dump will output the variable as is, so if it contains HTML the browser will parse it and you won't see the HTML part (only in view source).

try to escape it before using var_dump.

var_dump(htmlspecialchars($input));
Sign up to request clarification or add additional context in comments.

Comments

0

Can you take a look at the page source for the page where you're doing the var_dump? I suspect your browser is actually parsing the div and b tags, so the HTML is not showing up in the text...

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.