1

我希望这与 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);

我创建了一个带有参数的函数的控制器并更改了以前的代码:

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

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

我使用这条路线(但不起作用):

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

我遇到的问题是我只收到最后一封信。例如,如果我写“name”,只有“e”它作为参数传递。但是所有的消息都发送了。 我的控制器功能如下所示:

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>';
}
4

1 回答 1

1

仅使用

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

文档

于 2013-02-23T13:15:35.273 回答