【发布时间】:2011-12-03 13:30:11
【问题描述】:
我有 2 个相同的代码块,当它首先从控制器中的索引加载时它可以工作,但是当我提交表单并加载此代码时,我的自动完成功能不适用于字段。
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>public/blue.css" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" />
<script type="text/javascript" src="<?php echo base_url(); ?>public/jquery-1.6.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('workin');
//$(".publish-bottom").hide();
$(".publish-right").hide();
//title field
$.ajax({
type: "GET",
cache: false,
dataType: 'json',
url: "publishlinks/search_movies",
success:
function(response) {
alert('response received');
alert(response);
$("#title").autocomplete({
source: response,
minLength: 2,
select: function (event, ui) {
var selectedObj = ui.item;
var imgFilename = ui.item;
imgFilename = imgFilename.value;
imgFilename = imgFilename.replace(/ /g,"_");
$(".selected-right").empty();
$(".selected-left").empty();
$(".publish-right").show();
//render selected media
$(".selected-left").append('<a href="<?php echo "#"; ?>"> <img class="movie-img" src="<?php echo base_url(); ?>img_test/' + imgFilename + '"></a>');
$(".selected-right").append('<h4>' + selectedObj.title + '</h4>');
$(".selected-right").append(selectedObj.plot);
//update publication id
$("#movieId").attr("value", selectedObj.movieid);
$("#selected-item").attr("value", "selected");
$(".new-movie").show();
//get selected item's publications
getPublications(selectedObj);
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
var imgFilename = item.label;
imgFilename = imgFilename.replace(/ /g,"_");
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( '<a>' + '<img src="http://localhost/portal/img_test/' + imgFilename + '" width="40" height="63" />' + item.title + '</a>' )
.appendTo(ul);
}
}
});
});
</script>
function search_movies() {
$movies = $this->movie_model->get_movies();
echo json_encode($movies);
}
//works fine
function index() {
$this->load->model('user_model');
$data['user'] = $this->user_model->get_user($this->session->userdata('userid'));
$data['loggedIn'] = $this->is_logged_in() ? true : false;
$this->load->view('header_view', $data);
$this->load->view('publish_links_view');
}
表单提交代码:
//Not working for autocomplete
$error['linksError'] = 'You must select an item to publish links for.';
$data['user'] = $this->user_model->get_user($this->session->userdata('userid'));
$data['loggedIn'] = $this->is_logged_in() ? true : false;
$this->load->view('header_view', $data);
$this->load->view('publish_links_view', $error);
【问题讨论】:
-
该代码没有告诉我们,请发布您所指的实际功能
-
response会是什么?除非它是 URI/URL,否则它很可能不起作用。 -
@Nathan Hoad 为什么不呢?这是一个 json 格式的字符串。
-
"只需指定源选项,即可自定义自动完成以使用各种数据源。数据源可以是:具有本地数据的数组、字符串、指定 URL、回调"@ 987654321@
标签: php jquery codeigniter relative-path