Reputation: 61
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));
Upvotes: 0
Views: 1355
Reputation: 3973
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...
Upvotes: 0
Reputation: 319
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));
Upvotes: 1