代码点火器路由.AJAX使用javascript获取参数

Codeigniter routing. AJAX get with parameters using javascript

本文关键字:javascript 获取 参数 使用 AJAX 点火器 路由 代码      更新时间:2023-09-26

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

仅使用

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

文件。