简体   繁体   English

在 Codeigniter 中使用或不使用斜杠的 Ajax 数据调用出现错误

[英]Ajax Data Call with or without slash in Codeigniter getting error

suppose my URL is example.com/controller/method/假设我的 URL 是example.com/controller/method/

when I use this ajax code it makes URL like example.com/controller/method/method which not getting data.当我使用这个 ajax 代码时,它使 URL 像example.com/controller/method/method一样没有获取数据。

    function getProductList() {
    var category = document.getElementById('Category').value;

    $.ajax({
        type: 'POST',
        url: 'GetProductList',
        data: {CategoryId: category},
        dataType: 'json',
        cache:false,
        success: function (response) {

        }
    });
}

but when my URL is example.com/controller/method then ajax getting data correctly.但是当我的 URL 是example.com/controller/method 时, ajax 会正确获取数据。 but i want to get data from the database on both situations.但我想在这两种情况下从数据库中获取数据。

Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method.通常,URL 字符串与其对应的控制器类/方法之间存在一对一的关系。 So you can not use example.com/controller/method/method .The segments in a URI normally follow this pattern: example.com/class/function/id/ , So your last method argument treated as a id.所以你不能使用example.com/controller/method/method 。URI 中的段通常遵循这种模式: example.com/class/function/id/ ,所以你的最后一个方法参数被视为一个 id。 so create method in controller with the default argument Ex.所以使用默认参数Ex在控制器中创建方法 public function mymethod($method = ''){ /** Your logic goes here */ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM