Home > database >  Jquery AJax URL return 404-not found in iis
Jquery AJax URL return 404-not found in iis

Time:12-23

hy, I have a ajax function like below in my ci3 application:

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

});

This work perfectly when i run the application from visual studio but when i deployed this in to IIS my ajax function is not working, and give me error: enter image description here I tried the URL as url: '../myController/myFunction' or
url: '<?php echo base_url('login/login') ?>' then it still same, not work at local level also

this is my controller function

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);
    }
}

and this is my base_url config:

$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']);

did i must changemy config ?

CodePudding user response:

this is funny, but the problem its i cant use my .htacces and must to change it to web.config to make it works, this is the code i got from another post that help me

<?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>
  • Related