Jump to content
Sign in to follow this  

added data in todo list is not visible without refreshing

Recommended Posts

Hello All,


New Year Greetings!!


I have integrated a script for TODO list in my website. Its working fine, but adding New task will be appear only after refreshing the page, whereas delete and save are happening as and when i click on them. I dont know where can i make it right.


Here is my code



<div class="w-box-content todo-list">
                               <ul class="todoList">
		require "todo.class.php";
$query = mysql_query("SELECT * FROM `tz_todo` ORDER BY `position` ASC");

$todos = array();

while($row = mysql_fetch_assoc($query)){
	$todos[] = new ToDo($row);
		foreach($todos as $item){
			echo $item;


<a id="addButton" class="green-button" href="#">Add a ToDo</a>
<div id="dialog-confirm" title="Delete TODO Item?">Are you sure you want to delete this TODO item?</div>

I am including

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/humanity/jquery-ui.css" type="text/css" media="all" />
            <link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript" src="script.js"></script>

 and in ajax.php

require "connect.php";
require "todo.class.php";

$id = (int)$_GET['id'];


		case 'delete':
		case 'rearrange':
		case 'edit':
		case 'new':

catch(Exception $e){
//	echo $e->getMessage();

echo "1";

Share this post

Link to post
Share on other sites

You can do that from your script.js page. Inside the sucess part of the script, you can add something like:

$("#todoList").load( "index.php #todoList");

In order for this to work, add an id attribute to the <ul class="todoList"> like this <ul class="todoList" id="todoList">

Then in the code i provided insert the URL of your totdo page at the place of index.php


This will fetch the page, retreive the #todoList content and replace it and all that with out refreshing the users page ... only the content will change.

Edited by drisate
  • Like 1

Share this post

Link to post
Share on other sites



I have made changes like this in my script.js

	/* The following code is executed once the DOM is loaded */

		axis		: 'y',				// Only vertical movements allowed
		containment	: 'window',			// Constrained by the window
		update		: function(){		// The function is called after the todos are rearranged
			// The toArray method returns an array with the ids of the todos
			var arr = $(".todoList").sortable('toArray');
			// Striping the todo- prefix of the ids:
			arr = $.map(arr,function(val,key){
				return val.replace('todo-','');
			// Saving with AJAX
		/* Opera fix: */
		stop: function(e,ui) {
	// A global variable, holding a jQuery object 
	// containing the current todo item:
	var currentTODO;
	// Configuring the delete confirmation dialog
		resizable: false,
		modal: true,
		buttons: {
			'Delete item': function() {
			Cancel: function() {

	// When a double click occurs, just simulate a click on the edit button:
	// If any link in the todo is clicked, assign
	// the todo item to the currentTODO variable for later use.

	$('.todo a').live('click',function(e){
		currentTODO = $(this).closest('.todo');

	// Listening for a click on a delete button:

	$('.todo a.delete').live('click',function(){
	// Listening for a click on a edit button
	$('.todo a.edit').live('click',function(){

		var container = currentTODO.find('.text');
			// Saving the current value of the ToDo so we can
			// restore it later if the user discards the changes:
			// This will block the edit button if the edit box is already open:
			return false;
		$('<input type="text">').val(container.text()).appendTo(container.empty());
		// Appending the save and cancel links:
			'<div class="editTodo">'+
				'<a class="saveChanges" href="#">Save</a> or <a class="discardChanges" href="#">Cancel</a>'+
	// The cancel edit link:
	$('.todo a.discardChanges').live('click',function(){
	// The save changes link:
	$('.todo a.saveChanges').live('click',function(){
		var text = currentTODO.find("input[type=text]").val();
	// The Add New ToDo button:
	var timestamp=0;

		// Only one todo per 5 seconds is allowed:
		if((new Date()).getTime() - timestamp<3000) return false;
		$.get("ajax.php",{'action':'new','text':'New Todo Item. Doubleclick to Edit.','rand':Math.random()},function(msg){

			// Appending the new todo and fading it into view:
			$("#todoList").load( "index.php #todoList");

		// Updating the timestamp:
		timestamp = (new Date()).getTime();
}); // Closing $(document).ready()

and in index.php

<ul class="todoList" id="todoList">

But when i click on add, everything goes off , after refreshing it will appear again. 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.