Codeigniter Ajax在主机上调用404错误 [英] Codeigniter ajax call 404 error on hosting

查看:110
本文介绍了Codeigniter Ajax在主机上调用404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在托管上测试一个Codeigniter Proyect;它呈现的索引页没有问题,但是我有一个联系表单,该表单通过ajax请求发送数据,这里:

I'm trying to test a codeigniter proyect on hosting; the index page it's rendering without problems, but I have a contact form that sends data via an ajax request, here:

$('#send_mail').submit(function(e) {
e.preventDefault();

$.ajax({
  url: baseurl+'email/send',
  type: 'POST',
  dataType: 'json',
  data: $(this).serialize()
})
.done(function() {
  console.log("success");
})
.fail(function() {
  console.log("error");
})
.always(function() {
  console.log("complete");
});

});

我提交联系表格时出现此错误:

When I submit the contact form I'm getting this error:

 POST http://novaderma.cl/site/email/send 404 (Not Found) jquery.min.js:4

我一直在网上搜索,其他人也对 .htacces 文件和 base_url 参数有类似的问题,所以我也要在此处发布它们:

I've been searching on the web and other people have similar problems with the .htacces file and base_url parameter, so I'm gonna post them too, here:

配置文件

$config['base_url'] = 'http://novaderma.cl/site/';
$config['index_page'] = 'index.php';

.htaccess

.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /site/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
  </IfModule>

我不知道如何解决这个问题,所以请帮助我!

I don't know how to solve this, so please help me !!

推荐答案

您的站点服务器可在Windows的IIS上运行,因此.htaccess不会帮助您,因为它适用于Apache服务器.

Your site server works on IIS on Windows so .htaccess won't help because it's for an Apache server.

您需要在 site 文件夹中创建 web.config 文件,然后使用以下规则填充该文件:

You need to create web.config file in site folder, then fill it with the folllowing rule:

<rewrite>
        <rules>
             <rule name="Clean URL" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/site/index.php/{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>

这篇关于Codeigniter Ajax在主机上调用404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆