Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery+AJAX delete anchor not working
    primarykey
    data
    text
    <p>Hi I'm using jQuery and Codeigniter. I'm creating a simple todo list that can add delete entries using ajax.</p> <p>The problem is whenever I click on my delete anchor, it won't delete the entry. The adding of the entry feature works BTW.</p> <p>Here's my code:</p> <p>todo_view.php</p> <pre><code>&lt;html&gt; &lt;head&gt;Todo List&lt;/head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#submit').click(function() { var msg = $('#message').val(); $.post("&lt;?= site_url('todo/add') ?&gt;", {message: msg}, function() { $('#content').load("&lt;?= site_url('todo/view/ajax') ?&gt;"); $('#message').val(''); }); }); $('a.delete').click(function() { var id = $('input', this).val(); $.post("&lt;?= site_url('todo/delete') ?&gt;", {todoid: id}, function() { $('#content').load("&lt;?= site_url('todo/view/ajax') ?&gt;"); }); }); }); &lt;/script&gt; &lt;body&gt; &lt;div id="form"&gt; &lt;input type="text" name="message" id="message" /&gt; &lt;input type="submit" name="submit" id="submit" value="Add todo" /&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;?php $this-&gt;load-&gt;view('message_list'); ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>message_list.php</p> <pre><code>&lt;ol&gt; &lt;?php foreach ($todolist as $todo): ?&gt; &lt;li&gt; &lt;?php echo $todo-&gt;todo; ?&gt; &lt;a href="#" class="delete"&gt;&lt;input type="hidden" value="&lt;?=$todo-&gt;todoid ?&gt;" /&gt;delete&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ol&gt; </code></pre> <p>Why doesn't it work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload