dongwenxiu5200
2012-04-11 09:00
浏览 47
已采纳

通过jquery ajax将文本区域中的内容加载到div中

I need to load content from a text area into a div via jquery ajax. The content initally loads into a div via jquery. When the button is pressed, a click function inserts the content into a database via ajax and then reloads the content back into the div. It works but seems to be a bit sporadic. My question is, is there a better way to do this.

I am basically trying to submit a status into a timeline without refreshing the page

<script>
    $.ajaxSetup ({ cache: false });     
    var ajax_load = "<div align='center'><img src='img/ajax-loader.gif' alt='loading...' /></div>";
    var loadUrl = "ajax/ajax.php";
    var loadMe = "functions/status.php";
    $("#result").html(ajax_load).load(loadUrl);

    $("#share-but").click(function() {
        var status = $("textarea#status").val(); 
        $.post(
            loadMe,
            { status: status, user_id: '<?php echo "10" ?>' },
            "html"
        );
        $("#result").html(ajax_load).load(loadUrl);
        $("textarea").val('Share an update');
    });
</script>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题