jquery javascript在codeigniter中不起作用(jquery javascript doesnt work in codeigniter)

大家好,感恩节快乐!

我在codeigniter中包含此脚本是一个问题:

<script type="text/javascript" src="<?php echo base_url();? application/views/jquery.js"> </script> <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('<?php $this->load->view('data');?>') //im tryng also $('#show').load('<?php echo base_url();?>application/views/data.php') but it doesnt work anyway }, 3000); }); </script>

这个功能输出codeigniter工作没有问题? 也许我在配置文件中有一些问题? 艾特知道...请写信给我抱歉英语不好的问候

Hi everybody and happy thanksgivingday !

i am some problem to include this script in codeigniter:

<script type="text/javascript" src="<?php echo base_url();? application/views/jquery.js"> </script> <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('<?php $this->load->view('data');?>') //im tryng also $('#show').load('<?php echo base_url();?>application/views/data.php') but it doesnt work anyway }, 3000); }); </script>

this function out codeigniter work without problem ? maybe i have some problem in configuration file ? idont know ... please write me sorry for the bad english best regards

最满意答案

另一种方法如下。

<script type="text/javascript" src="<?= base_url('application/views/jquery.js'); ?>">

在这种情况下, $config['base_url']有一个尾随/

如果您尝试直接在应用程序/视图下访问文件,则会出现404错误。 那是你的问题吗?

通常你会将所有公共端css和js文件放在像......这样的结构下

Your Document Root Folder/ assets/ js/ jquery.js css/

那么你会有

<script type="text/javascript" src="<?= base_url('assets/js/jquery.js'); ?>">

然后你可以正确访问它。

诀窍是...在浏览器上查看您的HTML源代码,查看您的jquery链接,然后单击它,看看好的错误消息说明了什么。

如果一切正常,那么您将看到实际的文件源。

An alternative way is as follows.

<script type="text/javascript" src="<?= base_url('application/views/jquery.js'); ?>">

In this case $config['base_url'] has a trailing /

If you are trying to access files directly under applications/views you will get a 404 error. Is that your issue?

Normally you would put all your public side css and js files under a structure like...

Your Document Root Folder/ assets/ js/ jquery.js css/

So then you would have

<script type="text/javascript" src="<?= base_url('assets/js/jquery.js'); ?>">

And then you can access it correctly.

The trick is... view your HTML source code on the browser, view the link you have for your jquery and click on it and see what the nice error message says.

if it all works, then you will see the actual file source.

更多推荐