Experiencing issues with Ajax Data Call in Codeigniter, whether or not a slash is included

If my URL is example.com/controller/method/,

using this ajax code changes the URL to example.com/controller/method/method which is not retrieving data.

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

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

        }
    });
}

However, if the URL is example.com/controller/method, the ajax call retrieves data correctly. I need to be able to access data from the database in both situations.

Answer №1

Usually, there is a direct correlation between a URL string and its corresponding controller class/method. This means that you cannot have something like example.com/controller/method/method. The segments in a URI typically follow this format: example.com/class/function/id/. Therefore, the last method argument is usually treated as an id. To handle this, create a method in the controller with a default argument like this: For example,

public function mymethod($method = ''){ /** Your logic goes here */ }
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve information from a text

I retrieved this data as a string from a webpage using jQuery and need help parsing it. When I attempted to use jQuery.parseJSON, I encountered the error Uncaught SyntaxError: Unexpected token n. The specific values I am looking for are "surl" and "imgur ...

Transferring a child component (dropdown menu) to the parent component using React-Hook-Forms: Reference is not considered a prop and values are not retained upon submission

I am encountering issues with a dropdown component named Size nested within a parent component that utilizes useFieldArray. Every time I submit the form, I receive warnings and no values are displayed in the console. How can I resolve this issue? These ar ...

Iterate through the list elements by utilizing jQuery

I am working with HTML code that looks like this: <ul class="lorem"> <li>text</li> <li>text</li> <li>hello</li> <li>text</li> </ul> Can someone help me figure out how to loop through ...

Error: The "map" property cannot be read if it is undefined in a Django and React application

While I was following the react and django tutorial, I encountered an issue when I added some code for concern with. The error message 'Cannot read property 'map' of undefined' keeps getting thrown. The error location is pointed out ...

Include CakePHP named parameters in the URL when selecting from a list

If I have a selection list like the one below: <select name='languages'> <option value='german'>German</option> <option value='english'>English</option> </select> How can I use Jav ...

EaselJS BitmapAnimation has delay when using gotoAndPlay

I have created a requirejs module that enhances the functionality of a BitmapAnimation by allowing it to move around the stage at a specific speed and transition to another looped animation once reaching its destination. The issue I am encountering is a n ...

Enhancing time slot height on Fullcalendar V5: A step-by-step guide

Curious about adjusting the height of time slots in Fullcalendar V5 - any tips? ...

Tips for utilizing props in a Vue component

When trying to incorporate a prop into a computed value, I encounter the following error: [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined" found in ---> at src/cmps/space-details/space-imgs.vue at src/pa ...

Generating a fresh document in MongoDB using Mongoose, complete with references and assigned ObjectIDs

I've been attempting to use the mongoose create function in order to generate a new document with references, but I'm encountering an error when trying to provide objectIds for those refs. Despite my efforts to find a solution, I have been unsucc ...

How can I access data from a function that is executed within a method in Vue.js?

When working with vuejs and JS scopes, passing a value to a style property inside data can be tricky. The issue arises when trying to access this.data.property: Vue.component ('loader-component', { template: '#loader-template', mo ...

Load the flexslider once the fancybox container is opened

In my experience, I have found flexslider and fancybox to be very useful plugins. Individually, they work perfectly fine on a website that I am currently working on. However, when I tried placing a flexslider gallery inside a fancybox div, I encountered a ...

Unable to successfully create a dynamic anchor tag and open it in a new tab

I am receiving a PDF link in an AJAX response and I would like to manually trigger the download. Here is the code that I am currently using: var fileLink = document.createElement('a'); fileLink.href = responseData.PDF_LINK; fileLink.setAttribute ...

The JavaScript file fails to load when accessing port 8080

As I embark on my journey into backend development, please bear with me. Currently, I am working on a JavaScript program that retrieves text data from my localhost. I have set up an HTTP server using Node.js which serves as a regular HTTP server. The serve ...

Tips for declaring a particular type during the process of destructuring in Typescript

I have my own custom types defined as shown below: export type Extensions = | '.gif' | '.png' | '.jpeg' | '.jpg' | '.svg' | '.txt' | '.jpg' | '.csv' | '. ...

What steps can I take to avoid receiving an error stating that parameter 1 is not of type 'Node'?

I encountered the following error message: Uncaught TypeError: Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'. I am unsure why this error is occurring. It works fine on localhost ...

Cutting-edge framework for Single Page Applications

Can you assist me in identifying the most recent framework suitable for creating single page applications? Your help is greatly appreciated. Thank you. ...

Modify the value of a service from the main controller

I have been researching extensively on how to edit a service value from a nested controller. The issue I am facing is that my child controller needs to update a specific value in a service, and this value must be reflected in the parent controller as well. ...

Having trouble executing "npm install" following the clone from GitHub in React

After cloning a repository from GitHub, I attempted to run "npm install" but encountered the following error: https://i.sstatic.net/QM4RZ.png Since the project is still in development, should I install or add anything else to successfully run it? ...

Dompdf is unable to process data exceeding two pages

Having 85 rows in a table with dompdf is functioning properly, but when exceeding 85 rows, they are not displaying on the 3rd page; instead, they are overlapping on the 2nd page. Incorporating dompdf with codeigniter, I've attempted removing all styl ...

Using a simulation to deactivate webpage elements and showcase the UpdateProgress control

I am currently attempting to disable certain page elements and display an update progress control in my application. In order to achieve this, I have applied a style sheet with the property filter: alpha(opacity=85); However, I encountered an error stati ...