nax3t / ajax-jquery-tutorial Goto Github PK
View Code? Open in Web Editor NEWLearn AJAX with jQuery
Learn AJAX with jQuery
We only updated the markup of the index.ejs file but not the markup embedded in the ajax POST request's string template literal. It still looks like this:
<li class="list-group-item">
<span class="lead">
${data.text}
</span>
<div class="pull-right">
<a href="/todos/${data._id}/edit" class="btn btn-sm btn-warning">Edit</a>
<form style="display: inline" method="POST" action="/todos/${data._id}">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</div>
<div class="clearfix"></div>
</li>
Thus, when a new ToDo is dynamically created the edit button (which is here still an anchor tag) directs the user to the old edit page and we never see the ajax edit request's callback function update the DOM.
For this to work as intended, the ajax POST request's string template literal should have the following markup:
`
<li class="list-group-item">
<form action= "/todos/${data._id}" method="POST" class="edit-item-form">
<div class="form-group">
<label> Item Text </label>
<input type="text" value = "${data.text}" name="todo[text]" class="form-control">
</div>
<button class="btn btn-primary"> Update Item </button>
</form>
<span class="lead">
${data.text}
</span>
<div class="pull-right">
<button class="btn btn-sm btn-warning edit-button"> Edit </button>
<form style ="display: inline" method ="POST" action="/todos/${data._id}" class="delete-item-form">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</div>
<div class="clearfix">
</div>
</li>
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.