Events on ajax-got HTML form
So, this is JavaScript
- $(document).ready(function(){
- $('#lgn_form').submit(function() {
- ajax($(this).serialize(),'toolSection','lgn_form');
- return false;
- });
- });
- function ajax(data,section,source) {
- $.ajax({
- type: "POST",
- url: "core/ajax.php",
- data: data+'§ion='+section+'&source='+source,
- success: function(html){
- id = "#"+section;
- $(id).html(html);
- }
- });
- }
I use this, to manage user login-session, into small container inside my page.
I wont post whole PHP here, but the thing is, when I send data to server and it receives an answer, I clear a contents of container (in which, login form resided), and insert my answer. Problem comes, when there is situataion, when login fails, it gives in response a new login form, with same ID (#lgn_form), but JavaScript does not "see" that ID, so it does not respond, on submit button.
It there any solution to make JS respond to ajax generated content ID's?