codeigniter 中的 jquery.ajax
我在 codeigniter 中实现 jquery.ajax
时遇到问题。我想将控件发送到控制器的特定功能。我在我的 javascript 函数中设置 url,如下所示
var url='<?php echo('First/index');?>';
var ajaxoptions={url:url,success:submit_ajax_response};
First
是我的控制器,index
是我想要发送控件的函数。当我单击调用它的事件时,会形成以下 url
http://localhost/codeigniter/First/index
该 URL 很好,但会生成 404
错误。我已经在 zendframework 中多次完成此类操作,但无法在 codeigniter 中完成这项工作。我注意到一件事,如果我在网址中添加 index.php
,它就可以正常工作。通过添加index.php,url 变得就像
http://localhost/codeigniter/index.php/First/index
我很惊讶如何从路由文件中删除index.php 一样。我的route.php 文件中只有两行,
$route['default_controller'] = "First";
$route['404_override'] = '';
我已经将控制器设置为默认控制器。 我做的对吗?问题是什么以及如何完成这项工作`
I am having a problem in implementing jquery.ajax
in codeigniter. I want to send the control to a specific function of a controller. I am setting the url in my javascript function like this
var url='<?php echo('First/index');?>';
var ajaxoptions={url:url,success:submit_ajax_response};
First
is my controller and index
is my function where I want to send the control. When I click on the event on which it is called the following url is formed
http://localhost/codeigniter/First/index
The URL is fine but it is generating the error of 404
. I have done such kind of operations various times in zendframework
but unable to accomplish this job in codeigniter. I have noticed one thing that if I add index.php
in the url it works fine. By adding index.php the url becomes like
http://localhost/codeigniter/index.php/First/index
I am astonished how to remove index.php from route file. I have only two lines in route.php file
$route['default_controller'] = "First";
$route['404_override'] = '';
I have already made my controller as the default controller.
Am I doing correct? What is the problem and how to accomplish this job`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要检查几件事。首先,在 /application/config/config.php 中确保索引文件设置为:
其次,确保您有正确的 .htaccess。这应该位于您的公共目录的根目录(与您的 index.php 位于同一位置):
You need to check a couple of things. First, in /application/config/config.php make sure index file is set to this:
Second, make sure you have correct .htaccess. This should be at the root of your public directory (same place as your index.php):
我注意到您的 URL 中缺少的部分是 CodeIgniter 具有的“index.php”内容。
将您的代码更改为:(您需要 URL 帮助程序,因此在此之前加载它):
index_page 返回您的网站“索引”页面,如配置文件中指定的那样。
要从 CodeIgniter 链接中删除 index.php,请参阅此处。
I notice the part that is missing form your URL is the "index.php" thing that CodeIgniter has.
Change your code to this: (You need URL helper, so load that before this):
index_page returns your site "index" page, as specified in your config file.
In order to remove index.php from your CodeIgniter links see here.