Form added to page

1

I have a javascript function that loads forms from XML files. The files contain only form codes, inputs, selects, etc ... This data is loaded dynamically to a page via the jquery load () function. Soon afterwards another function populates those fields retrieving data from a json array previously loaded. However, this data does not appear in the fields, as if the form was not loaded / synchronized on the page. Has anyone ever experienced this? Is there a light?

    
asked by anonymous 28.03.2017 / 21:37

1 answer

1

The method load() of JQuery is asynchronous.

What happens is that when you make the call, it probably has not yet generated the elements.

You can avoid this by using the callback method.

Ex:

$('#div').load('formulario.html',function(){
     //adicionar aqui o preenchimento dos campos
});
    
29.03.2017 / 01:33