0

如果不使用 Ajax 刷新页面,我将如何提交以下表单?我需要通过 'toid' 发送 user1_id 和来自 textarea 'newmsg' 的内容。

形式

<form action="insert.php" method="POST" class="form_statusinput">
<input type="hidden"  name="toid" value="<?php echo $user1_id ?>">
<span class="w">
<textarea class="input" name="newmsg" id="newmsg" placeholder="Say something" autocomplete="off"></textarea>
</span>
<button type="submit" value="Submit">Feed</button>
</form>
4

2 回答 2

2

1)在表单中添加一个ID,比如说“myform”。

2)然后您可以从此表单中获取所有字段并使用 AJAX 发送(不要忘记包括 jQuery):

        var form_data = $("#myform").serialize(); 
        $.ajax( 
        { 
            url: 'script.php', 
            type: 'POST', 
            cache: false, 
            data: form_data, 
            success: function(message) 
            { 
                ...
            }, 
            error: function(message) 
            { 
                ...
            } 
        }); 
于 2012-07-15T15:33:02.820 回答
0

如果 jQuery 是一个选项,那就很容易了。

请参阅 jQuery.post():http ://api.jquery.com/jQuery.post/

// Example: send form data using ajax requests
$.post("test.php", $("#testform").serialize());

有很多选项取决于您需要对返回值做什么,在这种情况下最好只阅读文档。

于 2012-07-15T15:34:23.767 回答