我的观点有所下降,
现在我想将POST数据发送到我的控制器,用于从<li></li>
标签中选择的项目。
基本上我想要的是当我从下拉列表中选择任何内容时我想触发java脚本将 POST 中的所选项目发送到我的控制器 < / p>
以下是我的下拉列表。我如何将fomr放在这里并将数据发送给控制器?
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Your Sites <span class="caret"></span></a>
<ul class="dropdown-menu">
<li onchange="this.form.submit()"><a href="#"><?php
foreach($sites as $site)
{
echo "<li>".$site->site_key."</li>";
}?></a></li>
</ul>
</li>
答案 0 :(得分:1)
您的网站
foreach($sites as $site)
{
echo "<li>".$site->site_key."</li>";
}?></a></li>
</ul>
</li>
<script>
$("#form_name").validate({
rules: {
dropdown: {
remote: "controller_name"
},
</script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
答案 1 :(得分:1)
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Your Sites
<span class="caret"></span></a>
<ul>
<?php
if (count($resultset) > 0) {
foreach ($resultset as $key => $val) { ?>
<li >
<a href="<?php base_url() ?>controller/function_name/?name=<?php echo $val['name'] ?>">
<?php echo $val['name'];}}?>
</a></li>
</ul>
//控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class demo extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('factory_model');
}
public function index(){
$data["master_title"] = $this->config->item('sitename')." | Factory";
$data['sort'] = $this->input->post("sort");
$data['resultset'] = $this->factory_model->factory();
$data["item"] = "Driver";
$data["master_body"]="demo";
$this->load->theme('layout',$data);
}
public function demo_name()
{
$name = $_GET['name'];
echo $name;
die;
}
}
// model
<?php
class factory_model extends CI_Model {
function __construct(){
parent::__construct();
}
public function factory(){
$this->db->select("*");
$this->db->from("factory");
$query = $this->db->get();
//echo $this->db->last_query();die;
$resultset = $query->result_array();
//debug($resultset);
return $resultset;
}
}