Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

php - Codeigniter ajax call 404 error on hosting

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

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 file

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...