Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery处理php元素循环_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如何使用jquery处理php元素循环

Javascript 如何使用jquery处理php元素循环,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有一个HTML表单,在插入查询成功后,它将使用jQueryAjax以HTML格式返回 comment.php $post_id=$_POST['id']; mysql_query("INSERT INTO comment(comment,post_id,)VALUES('$comment','$post_id')"); if(!mysql_errno()){ ?> <p><?php echo $comment; ?></p> 这是我的表格。它在用户

我有一个HTML表单,在插入查询成功后,它将使用jQueryAjax以HTML格式返回

comment.php

$post_id=$_POST['id'];
 mysql_query("INSERT INTO comment(comment,post_id,)VALUES('$comment','$post_id')");
if(!mysql_errno()){
?>
<p><?php echo $comment; ?></p>
这是我的表格。它在用户每次提交的帖子循环中运行

<form action="" method="POST" class="post_id" id="<?php echo $post_id; ?>">

    <span>Write a comment ...</span>
    </div>
    <div class="new-comment-line"></div><----here is a line before the comment initiates..--->
        <textarea class="the-new-com"></textarea>
        <div class="bt-add-com">Post comment</div>
</form>
Ajax请求出现问题后,当我的表单从comment.php返回HTML表单时的代码行。每次用户提交状态后,表单都会打印

我该如何处理表格?我希望每次仅在用户提交的特定帖子中打印我的评论。

显然,$(“.new comment line”)是一个类选择器,您正在选择该类中的所有元素。当您通过单击按钮启动函数时,我建议选择与单击按钮相关的正确元素。因此,单击按钮后,立即选择正确的元素:

var correctElement=$(this).siblings('.new-comment-line');
然后在需要时将html添加到其中:

correctElement.after(html); 
显然,$('.new comment line')是一个类选择器,您正在选择该类中的所有元素。当您通过单击按钮启动函数时,我建议选择与单击按钮相关的正确元素。因此,单击按钮后,立即选择正确的元素:

var correctElement=$(this).siblings('.new-comment-line');
然后在需要时将html添加到其中:

correctElement.after(html); 

请使用Mysqli或PDO,因为mysql在较新的PHP版本中已被弃用,请在查询中转义您的变量。您的代码根本不是防注入的。更多关于如何做到这一点的信息:兄弟!我很清楚mysql现在是一个贬值的版本。我的all quest不完全是关于php的,它是关于与jquery相关的,这只是一个代码示例,使其更易于理解,我还使用了mysqli程序。。所以,请给我如何使用jquery处理表单循环的解决方案,我只有在循环中创建的许多元素的同一类。。那么我如何处理每个表单上特定点击事件的特定元素呢。仅此而已。请使用Mysqli或PDO,因为mysql在较新的PHP版本中已被弃用,请在查询中转义您的变量。您的代码根本不是防注入的。更多关于如何做到这一点的信息:兄弟!我很清楚mysql现在是一个贬值的版本。我的all quest不完全是关于php的,它是关于与jquery相关的,这只是一个代码示例,使其更易于理解,我还使用了mysqli程序。。所以,请给我如何使用jquery处理表单循环的解决方案,我只有在循环中创建的许多元素的同一类。。那么我如何处理每个表单上特定点击事件的特定元素呢。就这些。