구체적으로 말하자면, example.php에서이 콘텐츠를로드하는 경우 class = "aj-cp"형식을보세요.이 클래스를 사용하여 Ajax (아래 코드)를 통해 사용자 의견을 보냅니다.
<form class="aj-c-p" action="set_comentario.php" method="post">
<input type="hidden" name="comment_id" value="'.$publicacion.'">
<input type="hidden" name="user_from" value="'.$profile_id.'">
<input type="hidden" name="dat_fullurl" value="'.$dat_fullurl.'">
<input type="hidden" name="photo_from" value="'.$renglon['foto'].'">
<input type="hidden" name="name_from" value="'.$renglon['nombre'].'">
<input type="hidden" name="current_date" value="'.'Enviado el: .date(d).'/'.date(m).'/'.date(y).' a la(s): '.date(H).':'.date(i).':'.date(s).'">
<div class="contenido-y-publicacion">
<textarea onClick="clearInterval(auto_refresh);" class="b_green" name="sub_com" class="area-nosize" aria-expanded="false" role="textbox" dir="ltr"> </textarea> <br/> <input class="c-button" type="submit" value="Comentar"> <br/> <br/> <div id="name-for-coms"><h3>Comentarios</h3></div> <div id="divisor-tres"></div><br/><br/></div>
</form>
Ajax :
$('.aj-c-p').submit(function(e) {
var data = $(this).serialize();
// Stop the form actually posting
e.preventDefault();
// Send the request
$.ajax({
type: "POST",
url: "set_comentario.php",
data: data,
cache: false,
success: function(html){
$('.b_green').val('');
}
});
});
그래서 어떤 이유로 example.php로 폼을 새로 고치면 ajax 코드가 제대로 작동하지 않는다고 생각합니다. 새로운 내용이 동적으로 추가되는 원인이라고 생각합니다. 누구나 동적으로 추가 된 클래스에 "aj-cp"클래스를 추가하는 방법을 알고 있습니다. 양식, 그것에 대한 방법이 있습니까?
다음과 같아야합니다.
$(document).on('submit' , '.aj-c-p', function(e) {
var data = $(this).serialize();
// Stop the form actually posting
e.preventDefault();
// Send the request
$.ajax({
type: "POST",
url: "set_comentario.php",
data: data,
cache: false,
success: function(html){
$('.b_green').val('');
}
});
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다