将值从编辑中传递到数据库

时间:2012-01-12 02:55:52

标签: jquery

任何人都可以帮助我获取编辑后的值并将其传递给数据库吗?我真的不明白jquery.inlineedit.js如何发挥作用。我应该使用什么参数来获取值并将其传递给PHP页面?

但这是我的部分代码:

<script type="text/javascript">

    $(document).ready(function(){
        $counter = 0;
        $(".editme2").inlineEdit({control: 'textarea'});
        $("#hide").click(function(){
            if ($counter < 10){ 
                $counter++;
                $('#container').show( );
                $('#container').append( '<div class="inside" style="background: yellow; width: 400px;"><p class="editme2" id="edited'+$counter+'">Click me to add text and drag me to where you want me to be</p></div>');
                $( '.inside' ).draggable({ containment: '#there' });
            }
        });
    });
</script>

这是我的HTML代码:

<body>
    <button id="hide">Add Text</button>
    <div id="container" align="center" style="display:none; background: blue; width: 600px;">
        </div>
    <div id="there" style="background: red; width: 600px; height: 500px;">
    <h3>drop here</h3>
    </div>
</body>

1 个答案:

答案 0 :(得分:0)

作者在选项中提供了“保存”钩子。您需要定义它,并为您的信息提供目标。有一个save exmaple具有适当的php file来处理表单。使用您的设置,它看起来像:

<script type="text/javascript">

    $(document).ready(function(){
        // setup common ajax setting
        $.ajaxSetup({
            url: 'save.php',
            type: 'POST',
            async: false,
            timeout: 500
        });
        $(".editme2").inlineEdit({
            control: 'textarea',
            value: $.ajax({ data: { 'action': 'get' } }).responseText,
            save: function(event, data) {
                var html = $.ajax({
                    data: { 'action': 'save', 'value': data.value }
                }).responseText;

                alert("id: " + this.id );

                return html === 'OK' ? true : false;
            }
        });
    });
</script>

由于他的示例保存到文本文件,您可能会对saving form submissions to a database的教程感兴趣。

这绝不是一项微不足道的任务,但肯定有许多在线教程用于处理PHP表格。