<select id="pasp_option"></select> 

-

 function generate_pasport() { $.post("<?php echo base_url();?>admin/generate_pasport", {}, function (data) { $("#pasp_option").html(data); }); } generate_pasport(); alert($("#pasp_option").html()); 
  • The reason is that the alert is executed first at least in the last place and $ ("# pasp_option") requests. Load (" test / admin / generate_pasport" ); after aaa = $ ("# pasp_option"). html (); alert (aaa); when you click "OK" how to make the first request sent? - Aidos
  • Put an alert next line after $("#pasp_option").html(data); - Vitalii Maslianok

1 answer 1

If we take for the fact that the page <?php echo base_url();?>admin/generate_pasport gives you the result in the form

 <option>a</option> <option>b</option> ... 

That error should not be.


Of course, js tags are needed here:

 <script> </script> 

+ In your case, the .load() operator is most suitable. Total, on an output we will receive a code:

 <select id="pasp_option"></select> <script> $("#pasp_option").load("<?php echo base_url();?>admin/generate_pasport"); </script> 
  • Yes it is! - Aidos
  • added answer - Vitalii Maslianok
  • alert ($ ("# pasp_option"). html ()); doesn't it work? - Aidos
  • everything should work. 99% error in the generate_pasport file. <?php echo base_url();?>admin/generate_pasport this link in the browser <?php echo base_url();?>admin/generate_pasport - do you see what the page should display? - Vitalii Maslianok
  • It does not work, it’s output <option value='3'>111</option><option value='6'>114</option> $ ("# pasp_option"). Load ("<? Php echo base_url ( );?> admin / generate_pasport "); This works $ ("# pasp_option"). Html ("<option value = '3'> 111 </ option> <option value = '6'> 114 </ option>"); aaa = $ ("# pasp_option"). html (); alert (aaa); - Aidos