gpt4 book ai didi

javascript - .JS 格式的 base_url

转载 作者:行者123 更新时间:2023-11-30 09:44:34 24 4
gpt4 key购买 nike

我的 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 的命令?谢谢

最佳答案

在您的页面标题中尝试这样做:

<header>
<script type="text/javascript">
var base_url = "<?= base_url() ?>";
</script>
</header>

然后在你的 .js 文件 url 变成

url: base_url + "ajax_upload_img_item.php", // Url to which the request is sent

关于javascript - .JS 格式的 base_url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com