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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:16:27+00:00 2026-05-22T21:16:27+00:00

I am currently using jquery to get JSON data via ajax from a codeigniter

  • 0

I am currently using jquery to get JSON data via ajax from a codeigniter backend / mySQL database, which works fine. The problem I’m having is that, along with the data that gets returned to the jquery function, I also need to run a PHP loop for some data in another table. Currently what I’m doing is waiting for an ajax success from the first function, then making another ajax call to the second function – but I know there is a way to do it with just one function, I’m just not sure how. Here are the two database queries:

function get_selected_member($member = null){
        if($member != NULL){
            $this->db->where('id', $member); //conditions
        }
        $query = $this->db->get('members'); //db name

        if($query->result()){
            $member_result = $query->row();
            return $member_result;
        }
    }

AND

function get_all_groups(){
        $query = $this->db->get('groups');
        $result = $query->result();
        return $result;
    }

and then in the javascript function, what I’m doing is saying:

var post_url = "/index.php/control_form/get_selected_member/" + selected_member_id;
$('#chosen_member').empty();
$.ajax({
    type: "POST",
    url: post_url,
    success: function(member)
    {
        //Add all the member data and...

        var post_url2 = "/index.php/control_form/get_all_groups/";
        $.ajax({
            type: "POST",
            url: post_url2,
            success: function(group)
            {
        //Create a dropdown of all the groups
            }
        });
    }
});
  • 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-22T21:16:28+00:00Added an answer on May 22, 2026 at 9:16 pm

    In PHP you can combine both in one then echo it to ajax as json variable. So in php you will need a change like following

    function get_member_with_group($member = null){
        $data['member'] = $this->get_selected_member($member);
        $data['group'] =  $this->get_all_groups();
        echo json_encode($data);
    }
    

    Then in javascript something like below..

    var post_url = "/index.php/control_form/get_member_with_group/" + selected_member_id;
    $('#chosen_member').empty();
    $.getJSON(post_url, function(response){
        var member = response.member;
        //do with member
        var group = response.group;
        // do with group
    });
    

    Hope this will help you 🙂

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

Sidebar

Related Questions

I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
I'm using the jQuery template plugin to generate HTML from JSON data which the
I am currently using jTemplate and jQuery to get airport data from a web
I'm using the JQuery AJAX function to deliver data to a PHP doc. Currently,
I'm currently attempting to retrieve a list of objects from my database using jQuery.
I'm currently using the following jQuery plugin: jQuery OEmbed. This plugin works great in
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I got a plugin which can load data using different methods. I'm currently using
I am using jquery ajax api to submit (POST/GET) a text as parameter to
Using the jQuery SelectBox plugin I'm trying to create a JSON object which looks

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.