I am working on special project and I almost finished it. My problem is *sending parameter to iframe*
.
My aim is to create simple editor like codepen or jsfiddle.
These are my ajax codes:
$.ajax({
data: {html: html, css: css, js: js},
success: function(r) {
if(r) {
$("#preview").html(r.preview);
} else {
alert("error");
}
}
});
My ajax.php
$html = $_POST["html"];
$css = $_POST["css"];
$js = $_POST["js"];
$r = array();
function d($html, $css, $js) {
$iframe .= '<iframe src="iframe.php">';
$iframe .= '</iframe>';
return $iframe;
}
$r["preview"] = d($html, $css, $js);
echo json_encode($r);
And finally my iframe.php
function prev($html = "", $css = "", $js = "") {
$iframe .= '<html>';
$iframe .= '<head>';
$iframe .= '<style>' . $css . '</style>';
$iframe .= '<script>' . $js . '</script>';
$iframe .= '<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>';
$iframe .= '</head>';
$iframe .= '<body>';
$iframe .= $html;
$iframe .= '</body>';
$iframe .= '</html>';
return $iframe;
}
echo prev(); // which parameters I use?
It is working but I didnt send parameter which comes from textarea? I didnt associate ajax.php and iframe.php.