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 6469181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:38+00:00 2026-05-25T05:57:38+00:00

What is the best way to address an AJAX script that sends data to

  • 0

What is the best way to address an AJAX script that sends data to POST in codeigniter? Right now I am loading a view with the AJAX through $this->load->view('AJAX', $data); however there is no UI or user actions in the view. It’s simply running through the script and returning POST data a little after the script loads. I receive the POST data in my model where I input the values into the DB and output some other values based on the data.

I need to open a real view, set metatags and re-direct the user to another website afterwards.

How do I address this?

The problem I’m facing is that I cannot open up another view because the AJAX view is the one that’s in focus but I need this AJAX view to be temporary that basically does it’s thing and sends to POST.

Is there any convention that I can lookup/research to what I’m describing? Let me know what kind of clarification is needed if any.

  • 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-25T05:57:38+00:00Added an answer on May 25, 2026 at 5:57 am

    Some people like to write “ajax” controllers and post to them exclusively, but you don’t need to do that. You can handle the request in the same controller that handles the non-ajax request. Personally, I exclusively return json, but you can return chunks of HTML if that works better for you.

    Your exact problem is vague (actual code would help clarify), but I think you are on the wrong track. Don’t use a view for processing anything ever. Use your Controller layer, this is for handling input and requests.

    Example of controller method responding to either ajax or non-ajax request:

    function edit_user()
    {
        $data['status'] = $this->user_model->save();
        if ($this->input->is_ajax_request())
        {
            // return json string with our update status
            // Something like: {"status":true}
            echo json_encode($data);
            exit;
        }
        // Load the non ajax view with the same data
        $this->load->view('users/edit', $data)
    }
    

    $this->input->is_ajax_request() is a function of the Input class that reads $_SERVER['HTTP_X_REQUESTED_WITH'] and checks if it’s value is XMLHttpRequest. This should only be true if it’s an “ajax” request.

    You can make life easier by wrapping this in a class or function. No matter what you decide to do, don’t use the view layer for processing data.


    I think my problem is, how do I address javascript without a view? how do I call the script and/or where do I put the JS code in the controller? I felt it was the wrong direction to address the code in a view but I didn’t see how else to do it.

    Whenever possible, you should put javascript code in a .js file and use a <script> tag to load it, in an HTML document. The only other exception is putting it in a “view” file (a file that’s only purpose is to construct your final HTML output). In other words, follow the same rules of HTML as to where to put javascript, and follow the usual conventions of MVC of where HTML belongs (in the view). Javascript code does not belong in your controller. Javascript is not processing your data, it is sending the data to the server.

    I need to open a real view, set metatags and re-direct the user to another website afterwards.

    If you want to load a view, then redirect (after a certain amount of time I assume), you can do it with javascript or a <meta> tag (but don’t use a meta tag, use js).

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

Sidebar

Related Questions

What's the best way to validate that an MAC address entered by the user?
What is the best way to determine if a string represents a web address?
What is the best way to verify/test that a text string is serialized to
I have a beginner question. What is the best way to address the change
what would be the best way to split this in python. (address, city, state,
What is the best way to compare a current website url in your address
Within Ruby on Rails, what's the best way to find out what data a
I've been tearing my hair out for a while now about the best way
I have problem to find the best way how isolate users data stored in
What is the best way deal with out-of-sequence Ajax requests (preferably using a jQuery)?

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.