javascript - addEventListener worked only for the first time -


I am using $ .post to load the registration form, the code below is loaded, its After this page uses XMLhtppRequest () to send form data and return response to the same page,

Whenever the register button is clicked the first time, everything is working fine , But if I want to resubmit the form then any validation errors, the script is not working Rega and full page will be reloaded.

  & lt; Form & gt; & Lt; Input type = "text" name = "email" placeholder = "email" /> & Lt; Button type = "submit" id = "register" & gt; Register & lt; / Button & gt; & Lt; / Form & gt; & Lt; Script & gt; Var Handling Control Process = Event (Event) {event.preventDefault (); Event.stopPropagation (); //console.log ($ ("input.email") Val ().); Var data = new form data (document.forms.namedItem ("register")); Var Requests = New XMLHttpRequest (); Request.open ('Post', 'url here'); Request.setRequestHeader ('cache-control', 'no-cache'); Request.send (data); Request.onreadystatechange = function () {if (request.readyState === 4) {$ ('selector here') Html (request.responseText) .show (); }}; }; Var register = document.getElementById ('Register'); Register.addEventListener ('click', handle registration registration); & Lt; / Script & gt;    

Can you change your # registry button with AJAX response to a new one? ? If this is the case, the event will not be attached to the new button.

If this is the case, then try to rejoin the incident in Ajax Ready Callback .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -