Jquery AJax URL return 404-在iis中找不到

Jquery AJax URL return 404-not found in iis

嘿,我的 ci3 应用程序中有一个如下所示的 ajax 函数:

$("#login").on('click', function() {
  $.ajax({
    url: '@Url.Action("login", "login")',
    type: 'POST',
    data: $('#quickForm').serialize(),
    dataType: 'JSON',
    success: function(data) {
      if (data.status) {
        toastr.success('Login Berhasil!');
        var url = '<?php echo base_url('dashboard') ?>';
        window.location = url;
      } else if (data.error) {
        toastr.error(
          data.pesan
        );
      } else {
        for (var i = 0; i < data.inputerror.length; i++) {
          $('[name="' + data.inputerror[i] + '"]').addClass('is-invalid');
          $('[name="' + data.inputerror[i] + '"]').closest('.kosong').append('<span></span>');
          $('[name="' + data.inputerror[i] + '"]').next().next().text(data.error_string[i]).addClass('invalid-feedback');
        }
      }
    }
  });

});

当我 运行 来自 visual studio 的应用程序时,这个工作完美,但是当我将它部署到 IIS 时,我的 ajax 功能不工作,并给我错误: 我试过 URL 作为 url: '../myController/myFunction'
url: '<?php echo base_url('login/login') ?>' 然后它仍然是一样的,在本地级别也不起作用

这是我的控制器功能

function login()
{

    $this->_validate();
    //cek username database
    $username = anti_injection($this->input->post('username'));

    if ($this->Mod_login->check_db($username)->num_rows() == 1) {
        $db = $this->Mod_login->check_db($username)->row();
        $apl = $this->Mod_login->Aplikasi()->row();

        if (hash_verified(anti_injection($this->input->post('password')), $db->password)) {
            //cek username dan password yg ada di database
            $userdata = array(
                'id_user'  => $db->id_user,
                'username'    => ucfirst($db->username),
                'full_name'   => ucfirst($db->full_name),
                'password'    => $db->password,
                'id_level'    => $db->id_level,
                'aplikasi'    => $apl->nama_aplikasi,
                'title'       => $apl->title,
                'logo'        => $apl->logo,
                'nama_owner'     => $apl->nama_owner,
                'logged_in'    => TRUE
            );

            $this->session->set_userdata($userdata);
            $data['status'] = TRUE;
            echo json_encode($data);
        } else {

            $data['pesan'] = "Username atau Password Salah!";
            $data['error'] = TRUE;
            echo json_encode($data);
        }
    } else {
        $data['pesan'] = "Username atau Password belum terdaftar!";
        $data['error'] = TRUE;
        echo json_encode($data);
    }
}

这是我的 base_url 配置:

$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

我必须更改我的配置吗?

这很有趣,但问题是我无法使用我的 .htaccess,必须将其更改为 web.config 才能使其正常工作,这是我从另一个 post 那里获得的代码,它有帮助我

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<system.webServer>

    <httpErrors errorMode="Detailed" />
    <asp scriptErrorSentToBrowser="true"/>

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

</system.webServer>

<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
</system.web>

</configuration>