javascript - Ajax call url in an external js file -


i have web page (written in php / codeigniter) uses javascript code.

i tried move javascript code external file better manage code. in document ready event load external file

$.getscript('<?php echo base_url();?>assets/js/offerta_editscontirow.js'); 

one piece of code, putted in external js file, not work; instead works correctly if put code inside main php file.

        $.ajax({             datatype: 'json',             url: '<?php echo site_url("offerta/applica_sconti");?>',             cache: false,             data: data,             success: function (data, status, xhr)         {  ........ 

it not work because not elaborate php code, , in query string find

"php echo site_url("offerta/applica_sconti");?>:"

so, there way have works? may pass parameter external js file while loading it, , pass url used in ajax call? other method?

kind regards, matt

try window.my_url = 'some value'; , variable below

window.my_url = '<?php echo site_url("offerta/applica_sconti");?>';  $.getscript('<?php echo base_url();?>assets/js/offerta_editscontirow.js'); 

and

$.ajax({             datatype: 'json',             url: my_url,             cache: false,             data: data,             success: function (data, status, xhr)         { 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -