Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:16:43+00:00 2026-05-13T18:16:43+00:00

I’m trying to perform an AJAX-request in a view, the user gives some input

  • 0

I’m trying to perform an AJAX-request in a view, the user gives some input which is sent to the server with AJAX and the function it’s supposed to go to is routed with CodeIgniters routes.

This is the view I’m currently standing in while making the request.

http://localhost:8888/companies/list

In my route config I’ve set this route below to handle the AJAX-request, which should be able to come from any view and still be able to go to the route I’ve specified.

$route['test_ajax'] = "ajax/test_ajax";

So the request should go to the “ajax”-controller and use the function “test_ajax”, which should make the POST-url look like this.

POST http://localhost:8888/test_ajax

But instead what I get is the current URL I’m standing at, and the route I’ve specified appended to the URL crashing my response from the AJAX-request completely since it didn’t even go close to the function it’s supposed to. The POST-url I get looks like this.

POST http://localhost:8888/companies/test_ajax

Notice how the parameter of /companies was removed. The argument /list was lost somewhere, al though if I add a trailing slash after the list I get the list argument in the URL as well.

So what just happened is that the POST tries to go to the companies-controller and look for the function test_ajax which is defined in the ajax-controller and not in the companies-controller. This error keeps occuring no matter what URL I’m at, and it always follows the same pattern. It keeps appending my route-URL to the existing URL instead of routing correctly.

So what could be causing the routing to behave this way, is there any setting that’s accidently enabled or anything? Because I know I’ve got this to work hundreds of times in previous projects.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:16:43+00:00Added an answer on May 13, 2026 at 6:16 pm

    It is because your Javascript is using the current directory as the base, and appending the AJAX URL to it. Because you are (to the client-side at least) in the companies directory, it appends your URL onto this.

    The solution, if your Javascript is inline, is to just use the base_url() PHP function wihtin the code …

    var url = '<?= base_url(); ?>test_ajax/'

    If your Javascript is not inline, you can declare a global variable at the top of your HTML document using the PHP function…

    var BASE_URL = '<?= base_url(); ?>'

    And use it everywhere else in your Javascript …

    var url = BASE_URL + 'test_ajax/'

    Alternatively, you could just hardcode your base URL, but that could get real messy real quick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to select an H1 element which is the second-child in its group
I need to clean up various Word 'smart' characters in user input, including but
I have a view passing on information from a database: def serve_article(request, id): served_article
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.