Jquery $.ajax上的查询字符串更改
我的问题是,当用post发送到CodeIgniter中的控制器时,我的数据内容发生了变化 我发送:Jquery $.ajax上的查询字符串更改,jquery,post,jquery-ui-sortable,Jquery,Post,Jquery Ui Sortable,我的问题是,当用post发送到CodeIgniter中的控制器时,我的数据内容发生了变化 我发送: item[]=113&item[]=114&item[]=164&item[]=125&item[]=163&item[]=131&item[]=130 并收到: item[]=113&item;[]=114&item;[]=164&item;[]=125&item;[]=163&item;[]=131&am
item[]=113&item[]=114&item[]=164&item[]=125&item[]=163&item[]=131&item[]=130
并收到:
item[]=113&item;[]=114&item;[]=164&item;[]=125&item;[]=163&item;[]=131&item;[]=130
我的看法是:
$(".todo-list").sortable({
update: function(event, ui) {
var path = "<?php echo base_url();?>news/sort_posts/";
var news_var = 'item[]=113&item[]=114&item[]=164&item[]=125&item[]=163&item[]=131&item[]=130';
// var news_var = $('.sortme').sortable('serialize');
console.log(news_var);
$.ajax({
type: 'POST',
url: path,
data: { news: news_var, <?php echo $this->security->get_csrf_token_name() ?> : '<?php echo $this->security->get_csrf_hash() ?>' },
dataType: "text",
cache:false,
success: function(data){ alert('success'); },
error: function(data){ alert("fail"); }
})
},
distance: 15
});
您需要将实际的项数组传递到数据对象中,让jQuery序列化它。它正在序列化导致问题的序列化字符串。否则,您还需要对其他数据执行所有序列化,并且只将序列化的字符串传递给
data
Hmm。。我想我明白了。。你想让我移动php的parse_str($news,$pageOrder);要在视图文件中使用jQuery吗?仍然无法使其工作。尝试了多种方法:)这帮助我解决了这个问题:
public function sort_posts()
{
$news = $this->input->post('news');
parse_str($news, $pageOrder);
if(!empty($news)) {
$this->db->insert('tester', array('test1' => '$news isset', 'test2' => $news));
} else {
$this->db->insert('tester', array('test1' => '$news empty'));
}
foreach ($pageOrder['item'] as $key => $value) {
$data = array('sort' => $key);
$this->db->where('id', $value);
$this->db->update('m_news_posts', $data);
}
}
// $news = item[]=113&item;[]=114&item;[]=164&item;[]=125&item;[]=163&item;[]=131&item;[]=130;