Git Product home page Git Product logo

ajax-jquery-tutorial's People

Contributors

nax3t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ajax-jquery-tutorial's Issues

ajax EDIT functionality not working on dynamically created new Todos.

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>
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.