2017-09-07 68 views
2

为什么我的函数没有被调用?我没有犯任何语法错误。为什么我的函数没有被调用?

另外,return false不是问题。我的功能仍然应该被调用。

<form onsubmit='createComment(commentType, currentQuestionID, $("#addCommentAuthor").val(), $("#addCommentEmail").val(), $("#addCommentContent").val(), $("#addCommentDate").val());return false;' method='POST'> 

var createComment = function(commentType, questionId, author, email, content, date) { 
    console.log('asd') 
    $.ajax({ 
     url: "controller.php", 
     type: 'POST', 
     data: { 
      commentType: commentType, 
      questionId: questionId, 
      add_comment_author: author, 
      add_comment_email: email, 
      add_comment_content: content, 
      add_comment_date: date 
     }, 
     success: function(data) { 
      console.log(data) 
     } 
    }) 
} 
+0

是您的脚本实际上在'script'标签/外部JS文件? –

+0

是的,先生它在脚本标记 – runucegop

+0

'createComment'定义在具有'form'的html块之后? – alexmac

回答

2

你应该改变函数名“createComment”,因为它是全球性的方法document.createComment()

+0

这并不奏效。 – runucegop

+2

@runucegop那么问题可能在其他地方,与bpu的解决方案工作正常:https://jsfiddle.net/yuriy636/ygbp806r/ – yuriy636

+0

你有什么提示在哪里? – runucegop

相关问题