tbduong / express-personal-api Goto Github PK
View Code? Open in Web Editor NEWThis project forked from sf-wdi-30/express-personal-api
Build an API about YOU
This project forked from sf-wdi-30/express-personal-api
Build an API about YOU
Several little issues with my "Create Entry" button:
Button is able to post/create , but is appending to the middle of the page on Heroku and end of the page in locally. Post is showing all data entered in the form, but won't show new "summary" and new "image" url.
"Create Entry" button works only after I refresh the page. Wondering what jQuery command is needed to make the buttons (delete button also) take effect immediately. Works in Postman.
$('#newTravelForm').on('submit', function(e) {
e.preventDefault();
$.ajax({
method: 'POST',
url: '/api/travels',
data: $(this).serialize(),
success: newTravelSuccess,
error: newTravelError
});
});
<div id="target">
<script id="travels-template" type="text/x-handlebars-template">
<table class="table">
<tbody>
<tr id=header>
<th>City</th>
<th>State</th>
<th>Country</th>
<th>Year Visited</th>
<th>Summary</th>
<th>Image Link</th>
</tr>
{{#each travels}}
<tr>
<td>{{city}}</td>
<td>{{state}}</td>
<td>{{country}}</td>
<td>{{year_visited}}</td>
<td>{{summary}}</td>
<td><img class="img-responsive" src="{{image}}"></td>
<td>
<button type="button" name="button" class="delete btn btn-danger center" data-id={{_id}}>Delete Entry</button>
</tr>
</tr>
{{/each}}
</tbody>
</table>
</script>
</div>```
Class and information matches up within html and js! Thinking I might have no drilled down enough for the id? And/or might have overlooked some syntax! DELETE method works with Postman, so not sure what the issue is. Here's the js and html.
$travelsList.on('click', '.delete', function() {
$.ajax({
method: 'DELETE',
url: '/api/travels/'+$(this).attr('data-id'),
success: deleteTravelSuccess,
error: deleteTravelError
});
});
<div id="target">
<script id="travels-template" type="text/x-handlebars-template">
<table class="table">
<tbody>
<tr id=header>
<th>City</th>
<th>State</th>
<th>Country</th>
<th>Year Visited</th>
<th>Summary</th>
<th>Image Link</th>
</tr>
{{#each travels}}
<tr>
<td>{{city}}</td>
<td>{{state}}</td>
<td>{{country}}</td>
<td>{{year_visited}}</td>
<td>{{summary}}</td>
<td><img class="img-responsive" src="{{image}}"></td>
<td>
**<button type="button" name="button" class="delete btn btn-danger center" data-id={{_id}}>Delete Entry</button>**
</tr>
</tr>
{{/each}}
</tbody>
</table>
</script>
</div>
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.