On a regular page there is a script that sets the verification of fields in the login and password modal window, I click submit in this popup, and the Ajax loads that the login and password is not correct, but after loading the Ajax, the following script simply does not work.

Why? For example, the script

$(".required").each(function(){}).on("blur", function() { if ($(this).val()!="") { if ($(this).hasClass("error")) { $(this).removeClass("error"); } }else{ if ($(this).hasClass("error")==false) { $(this).addClass("error"); } } }); 
It seems to be on .

Reported as a duplicate by Grundy , 0xdb , aleksandr barakin , andreymal , yolosora participants on Jan 11 at 5:54 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Fortunately, psychics do not exist. The SOru community is no exception. Provide the code, well, at least some, well, please :) - Alexxosipov
  • @Alexxosipov, I can’t imagine Ajax, because I don’t put in jffiddle, or I don’t understand something. Maybe it will be possible to understand the function? Help, pozh-hundred. - Rabin

2 answers 2

Using on does not mean automatic delegation of event handling. The handler must be fixed to the parent element with an indication of the selector for the elements that interest us.

 $(document).on("blur", ".required", function() { $(this).toggleClass("error", $(this).val() == ""); }); 

    Do this: (instructions for google chrome, although other browsers are able too)

    1) Press Ctrl + shift + i

    2) Go to the Network tab

    3) Click on your submit and you will see there a file which is a handler on the server.

    4) Click on it and see the Headers tab.

    5) At the very bottom, find Form Data here and see what happened and where the error hid

    Without code, this is all that I can advise.

    • Click on it and see the Headers tab. 5) At the bottom, find Form Data here and see what happened and where the error was hidden I did not find in the Headers tab in the network tab / Maybe you know a good article, otherwise I read learn.javascript .ru did not understand anything ... I would be grateful if you would help, thank you! - Rabin