我在script.js中有这段代码:
$(document).ready(function (e) {
$("#uploadimage").on('submit',(function(e) {
e.preventDefault();
$("#message").empty();
$('#loading').show();
$.ajax({
url: "ajax_upload_img_item.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
$('#loading').hide();
$("#message").html(data);
}
});
}));
我想加载ajax_upload_img_item.php但它不能正常工作,因为我没有base_url();命令就可以了。我不能在脚本上添加它。我将如何添加base_url();从Codeigniter配置到script.js的命令?谢谢
答案 0 :(得分:3)
答案 1 :(得分:1)
你需要这样做
<header>
<script type="text/javascript">
var BASE_URL= "<?php echo base_url() ?>";
</script>
<script type="text/javascript" src="<?php echo base_url();?>your_resource_folder_path/script.js"></script>
</header>
在script.js文件中
url: BASE_URL+ "ajax_upload_img_item.php",