1

I want this working with Codeigniter:

name = encodeURIComponent( document.getElementById("myName").value);

xmlHttp.open("GET", "quickstart.php?name=" + name, true);

xmlHttp.onreadystatechange = handleServerResponse; //not relevant for question

xmlHttp.send(null);

I have create a controller with a function with a parameter and changed the previous code:

xmlHttp.open("GET", "quickstart.php?name=" + name, true);

to

xmlHttp.open("GET", "ajax/quickstart/"+name, true);

I use this routes(but doesn't work):

$route['ajax'] = 'ajax';
$route['ajax/quickstart'] = 'ajax/quickstart';
$route['ajax/quickstart/([A-Za-z0-9])+'] = 'ajax/quickstart/$1';

The problem I'm having it's I only get the last letter written. For example if I write "name", only "e" it's passed as argument. But all the word was sent. My controller function looks like:

public function quickstart($name='')
{
// we'll generate XML output
header('Content-Type: text/xml');
// generate XML header
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
// create the <response> element
echo '<response>';
// retrieve the user name
//$name = $this->input->get('name');

// generate output depending on the user name received from client
$userNames = array('YODA', 'AUDRA', 'BOGDAN');
if (in_array(strtoupper($name), $userNames))
    echo 'Hello, master ' . htmlentities($name) . '!';
else if (trim($name) == '')
    echo 'Stranger, please tell me your name!';
else

echo htmlentities($name) . ', I don\'t know you!';
// close the <response> element
echo '</response>';
}

1 Answer 1

1

Use only

$route['ajax/quickstart/(:any)'] = "ajax/quickstart/$1";

Documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

It worked but I had to add $route['ajax/quickstart'] = 'ajax/quickstart/'; and $route['ajax/quickstart/(:any)'] = 'ajax/quickstart/$1';
@beerLantern, +1, That's perfect :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.