after use ajax function page keep reload

i have an link in my page as the following :

<input onkeydown="check_me(event,this,''. $post['id'] .'',''.$access_token.'');" id="comment_msg" type="text" size="40" placeholder="Write a comment" />

so am calling the following function :

function check_me(event,element,post_id,access_token){
    if(event.keyCode == 13){
        fb_comment(post_id, access_token,element);        
    }

}       
function fb_comment(post_id, token,element){                 
    jQuery.ajax({
        type: "GET",
        url: "comment_post.php",
        data: 'id='+post_id+'&token='+token+'&comment='+element.value,
        success: function(html)
        {           
          element.value='';                            
        }

    });    
}

problem is after submitting the the element value the page reload , how can i stop reloading the page after submitting the element value!!!

Answer

The browser tries to submit the form if you press return. So just add onsubmit=return false to your form tag – or remove it.

<form onSubmit="return false">
    <input onkeydown="...

Leave a Reply

Your email address will not be published. Required fields are marked *