开发者

Fetch texteditor value using jquery

I have a texteditor and I want to submit it's content to a php file using jquery.

My index file is:

<!--  jquery core -->
<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<!-- FCK editor Starts -->
<script src="texteditor/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
    new nicEditor({fullPanel : true}).panelInstance('area2');
});
</script>
<!-- FCK editor End -->
<script>
$(d开发者_如何学运维ocument).ready(function(){
    $("form#submit").submit(function() {
    // we want to store the values from the form input box, then send via ajax below
    var area2     = $('#area2').attr('value');
    var pageName     = $('#pageName').attr('value');
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: "pageName="+ pageName +"& textarea="+ area2,
            success: function(){
                $('form#submit').hide(function(){$('div.success').fadeIn();});

            }
        });
    return false;
    });
});
</script>
<div class="container">
<form id="submit" method="post">
        <textarea id="area2" name="area2" class="di"><div id="responsecontainer"></div></textarea>
        <input type="text" id="pageName" name="pageName" value="home" />
        <button>Submit</button>
    </form>
    <div class="success" style="display: none;">Client has been added.</div>
</div>

My ajax.php file is:

<?php
$pgName = $_POST['pageName'];
    $content = $_POST['textarea'];
    $content = str_replace('<div id="responsecontainer">','',$content);
    $content = str_replace("</div>",'',$content);

    $fp=fopen($pgName.'.html','w+');
    fwrite($fp,$content);
    fclose($fp);
?>

It works fine for textarea and textbox but does not fetch FCK texteditor contents.


Try the following:

var area2 = $('#submit .nicEdit-main').html();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜