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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:16:44+00:00 2026-06-10T17:16:44+00:00

I am using a codeigniter application that dynamically generates some html elements based on

  • 0

I am using a codeigniter application that dynamically generates some html elements based on a database query returned from a function in my model.

In one of my views I use XMLHttpRequest to call a php function in one of my controllers which in turn gets data from my model in the form of a string and echos it for the responseText. My javascript code looks like this:

var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "/controller/my_function", true);
var postStr = "name="+proposalName+"&data="+data;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(postStr);
var response = xmlHttp.responseText;

The called function looks like this:

public function my_function(){
$data['name'] = $this->input->post('name');
$data['data'] = $this->input->post('data');
$string = $this->my_model->my_model_function($data);
echo $string;
}

The model returns the string correctly, and even after just echoing a random number or string in the function it still didn’t get anything from the response text. No matter what i try to echo in the function there doesn’t appear to be anything in the response text. What am i doing wrong here? How can I get the responseText to grab the correct value from my php function?

Edit: fixed a copying issue with postStr variable

  • 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-06-10T17:16:46+00:00Added an answer on June 10, 2026 at 5:16 pm
    var post Str = "name="+proposalName+"&data="+data;
    

    That is a syntax error. The JavaScript falls over when it hits Str. The HTTP request is never sent.

    Even if it was sent, you are making an asynchronous request (the third argument to open is true) so it doesn’t lock up the entire page until the response is received. You would be reading xmlHttp.responseText before it was set by the response.

    You need an onreadystatechange function.

    See the MDN documentation for XMLHttpRequest which has examples.

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

Sidebar

Related Questions

In my LAMP application (using CodeIgniter), I have a call to $this->db->update... that generates
I have a codeigniter application.In that i call the controller function using ajax/jquery.But when
I just added a htaccess file to my codeigniter application that removes index.php from
I'v built a application using codeigniter and I have a message system that displays
In codeigniter application i pop up a window from a view page using href
I'm using CodeIgniter for an application that I'm writing and I've got a question
I am creating an application using CodeIgniter/MySQL. The problem is that when I store
I'm developing a PHP application using CodeIgniter as the framework, and PostgreSQL as the
I am using Codeigniter to develop an application, and have been reading bits about
I am using CodeIgniter to upload some files through a form. I know how

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.