gpt4 book ai didi

javascript - 实时更新有问题

转载 作者:行者123 更新时间:2023-12-03 12:12:34 25 4
gpt4 key购买 nike

我正在 CodeIgniter 中进行实时更新,它几乎可以工作了。

只有一个小问题:当我单击按钮时,它也会在“响应”框中显示我的导航,这非常奇怪。

当我刷新页面时,它被删除并且记录就在那里。

这是一张图片来解释我的意思

这是 JavaScript:

<script type="text/javascript">
$(document).ready(function() {

//##### Add record when Add Record Button is click #########
$("#FormSubmit").click(function (e) {
e.preventDefault();
if($("#contentText").val() ==='')
{
alert("Please enter some text!");
return false;
}

var myData = 'content_txt='+ $("#contentText").val(); //build a post data structure
jQuery.ajax({
type: "POST", // Post / Get method
url: "<?php echo site_url('admin/dashboard/index'); ?>", //Where form data is sent on submission
dataType:"text", // Data type, HTML, json etc.
data:myData, //Form variables
success:function(response) {
$("#responds").append(response);
},
error:function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
});

});
</script>

编辑:

这是 Controller

   class Dashboard extends CI_Controller
{
public function __construct()
{
parent::__construct();

// Load libraries
$this->load->library('ion_auth');
$this->load->library('parser');
// Load models
$this->load->model('note_model');
// Load helpers
$this->load->helper('date');
// Set error delimiters
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
}

public function index()
{
// Check if user is loged in
if (!$this->ion_auth->logged_in())
{
redirect('auth/login');
}
else
{
// Create notes object
$notes = new Note_model();
// Order the notes by date post
$notes->order_by('date_post', 'desc')->get();

$recent_notes = array();
foreach ($notes as $note)
{
$single_note = array
(
'id' => $note->id,
'note_text' => $note->note_text,
'date_post' => $note->date_post,
);
array_push($recent_notes, $single_note);
}

// Get the user id as an object
$getinfo = $this->ion_auth->user($this->session->userdata('user_id'))->row();

// Create a new note
$createNote = new Note_model();
$createNote->note_text = $this->input->post('content_txt');
$created = date('Y-m-d H:i:s');
$createNote->date_post = $created;

// Validation rules
$rules = $this->note_model->rules;
$this->form_validation->set_rules($rules);

$data = array
(
'admin_content' => 'admin/dashboard',
'notes' => $recent_notes,
'username' => $getinfo->{'first_name'} . ' ' . $getinfo->{'last_name'},
);

if ($this->form_validation->run() == FALSE)
{
$this->parser->parse('admin/template_admin', $data);
}
else
{
$createNote->save();
redirect('admin/dashboard');
}
}
}

最佳答案

问题在于您正在调用的操作。

似乎admin/dashboard/index输出导航以及您想要显示的数据。

您应该发布到仅显示您需要的数据的操作,而不显示其他内容

关于javascript - 实时更新有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24892118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com