我需要在成功动态创建表单提交后调用javascript ajax函数。
或者如何使用java脚本检查表单是否成功提交。
答案 0 :(得分:1)
以下是如何检查表单是否已提交以及如何处理回调的示例:
var form = document.querySelector('form');
var handleSubmit = function (e) {
// remove the preventDefault
// added just to demonstrate the value is true
// without proceeding with submittion and pg refresh
e.preventDefault()
form.setAttribute('data-submitted', true)
console.log(form.getAttribute('data-submitted'))
handleAjaxCall()
}
var handleAjaxCall = function () {
console.log('ajax call here!')
}
form.addEventListener('submit', handleSubmit, false)

<form data-submitted="0">
<button type="submit">submit</button>
</form>
&#13;