javascript - No response after form submission and page just auto reload -


i use ajax process form data submitted.

html form:

<div class="well"> <form id='createcommentform' method='post' onsubmit='createcomment();return false;'>     <h4>leave comment:</h4>     <div class="form-group">         <textarea class="form-control" rows="3" name='comment' id='comment'             placeholder='please input comments here ..' ></textarea>     </div>     <div class="form-group">         <input type='text' class="form-control" name='name' id='commenter'             placeholder='name of commenter'></input>     </div>     <div>         <input type='text' name='taskid' id='taskid'></input>     </div>     <button type="submit" class="btn btn-primary">submit</button> </form> </div> 

then using code below process form , pass value place in same html file form display.

js:

function createcomment() { $("#message").html(''); console.log("am in here?"); var commenter = $("#commenter").val(); var comment = $("#comment").val(); var taskid = $("#taskid").val(); var input = {}; input.commentername = commenter; input.message = comment; input.taskid = taskid; var inputstr = json.stringify(input); console.log(input); inputstr = encodeuricomponent(inputstr); $.ajax({     url : "/queuesystem/admin/createcommentservlet?input=" + inputstr,     method : "get",     datatype : 'json',     error : function(err) {         console.log(err);     },     success : function(data) {         console.log(data);         var status = data.status;         var message = data.message;         if (status == 1) {             var comment = message;             comments.push(comment);             console.log(comment);             var commentid = comment.commentid;             var message = comment.message;             var html = '\                 <div class="media">\                     <div class="media-body">\                         <h4 class="media-heading">' + comment.commentername + '\                             <small>' + comment.modifieddate + '</small>\                         </h4>'                         + message +                     '</div>\                 </div>';              $("#comments").append(html);          } else {             $("#message").html(message);         }     } }); 

}

my problem when press submit, page gets auto reload , seems no data passed through, or maybe function createcomment() not called @ all. cannot debug because page reload automatically , unusual me.

i have guess because when run it, third line in js not show on console.

but test servlet manually input data in url, call successful. suspect problem either in form or ajax.

can give me hint or suggestion or codes possibly went wrong?

many thanks!!

createcomment inbuilt function.

reference : developer.mozilla.org

try different function name.


Comments