0

少しのJQueryコードに問題があり、問題が何であるかわかりません。基本的に、ajaxを使用してその場でコメントを送信しようとしていますが、何らかの理由でページがリロードされ続けます。以下のコードをチェックしてください...

Htmlフォーム

<form method='post' action=''>                      
   <textarea name='comment' id='comment' maxlength='500'>Leave a Comment...</textarea>
   <input name='userActivityId' id='userActivityId' type='hidden' value='$userid'>

   <input class='send' id='formButton' type='submit' value='Send'>
</form>

JQueryコード

$(function(){

   /*this function submits a normal comment from the comment container*/
   $(".commentContainer .send").on('click', function(){     
      var profileId = $("input#userActivityId").val();
      var comment = $("textarea#activityComment").val();    

      if(profileId == ""){
         $("input#userActivityId").focus();
         return false;
      } 

      if(comment == ""){
         $("textarea#comment").focus();
         return false;
      } 

      //send message
      postActivityMessage(comment, profileId);

      return;
   });


   function postActivityMessage(comment, toUser){
      $.ajax({
         type: "POST", url: "include/process.php", 
         data:{
            addActivityComment: "true",
            message: comment,
            userActivityId: toUser,
            type: "message",
            replyto: '0'    
         },
         success: function(){
            alert('posted');
         }
      });
   }

});
4

1 に答える 1

1

デイブのコメントによると、これは役立つはずです

$("form").submit(function(e) {
    e.preventDefault();
});
于 2012-04-13T21:14:52.503 に答える