2012-04-13 7 views
0

Ich habe ein Problem mit ein wenig JQuery-Code und ich weiß nicht, was das Problem ist, im Grunde bin ich im Versuch, einen Kommentar auf den Fliege mit Ajax, sondern für einige Grund, dass die Seite neu geladen wird. Besuche unter den Code ...Ajax Post-Funktion lädt Seite statt dynamisch nur Daten senden

Html Form

<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-Code

$(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'); 
     } 
     }); 
    } 

}); 
+1

Sie‘Hilfe Die Standard-Ereignisbehandlung wird nicht abgebrochen. Warum nicht die ID des Knopfes benutzen? Gibt es eine ganze Reihe von ihnen? –

+0

@dave sorry was meinst du? Redest du über die Form Aktion? –

+0

ja theres ruhig ein paar der gleichen Tasten –

Antwort

1

Dies sollte laut Dave Kommentar

$("form").submit(function(e) { 
    e.preventDefault(); 
}); 
+0

danke das hat gut funktioniert –

Verwandte Themen