Codeigniter ajax在托管

时间:2017-01-23 01:49:17

标签: php ajax .htaccess hosting codeigniter-3

我试图在托管上测试codeigniter proyect;它没有问题的索引页面,但我有一个通过ajax请求发送数据的联系表单,在这里:

$('#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");
});

});

当我提交联系表单时,我收到此错误:

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

我一直在网上搜索,而其他人在使用.htacces文件和base_url参数时遇到类似问题,所以我也会发布这些问题,在这里:

配置文件

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

的.htaccess

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

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

2 个答案:

答案 0 :(得分:1)

您的站点服务器适用于Windows上的IIS,因此.htaccess无法提供帮助,因为它适用于Apache服务器。

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

<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>

答案 1 :(得分:-1)

`

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

`

检查此代码

相关问题