【问题标题】:Codeigniter ajax call 404 error on hostingCodeigniter ajax 在主机上调用 404 错误
【发布时间】:2017-06-07 11:33:48
【问题描述】:

我正在尝试在托管上测试 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>

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

【问题讨论】:

  • IIS 7 URL Rewriting的可能重复
  • 您的服务器在 Windows 上的 IIS 上运行,因此 .htaccess 无济于事,因为它用于 Apache 服务器。请参阅上面的 URL 以解决您的问题。
  • 嗨@Vaviloff! ,请你帮我解决这个问题吗?看不懂。
  • @Vaviloff 伟人!!!!!!!而已 !!谢谢 !!但我还有另一个问题,我认为它与此有关....我正在尝试通过 codeigniter 发送电子邮件并抛出类似的错误...“无法使用 smtp php 发送电子邮件,也许是您的服务器未正确配置为使用此发送方法”...任何想法? =(

标签: php ajax .htaccess hosting codeigniter-3


【解决方案1】:

您的站点服务器在 Windows 上的 IIS 上运行,因此 .htaccess 无济于事,因为它用于 Apache 服务器。

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

<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 发送电子邮件并抛出类似的错误...“无法使用 smtp php 发送电子邮件,也许是您的服务器未正确配置为使用此发送方法”...任何想法? =(
  • 太好了,很高兴为您提供帮助。至于 smtp 问题 - 请打开另一个问题,因为这是另一个问题。
  • 好的,我怎么能把你加到那个问题上呢? ...你能帮我吗?
【解决方案2】:

`

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

`

检查此代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 2017-01-26
    相关资源
    最近更新 更多