Closed ryanwk closed 7 years ago
If you console.log data
in the first line of removeExerciseRequest
, what does it show?
doesn't show
Anything? Not even undefined
? Make sure you're labeling it so that you can tell what you're looking at
ok got '88 this is data' 88 is the id
ok so I changed the api to this:
const removeExerciseRequest = (data) => {
console.log(data, 'this is data')
return $.ajax({
url: config.apiOrigin + 'exercises/' + data,
method: 'DELETE',
headers: {
Authorization: 'Token token=' + store.user.token
}
})
}
got this in the console:
jquery.js:3860 jQuery.Deferred exception: Cannot read property 'target' of undefined TypeError: Cannot read property 'target' of undefined
at onShowAllExercisesSubmit (http://localhost:7165/public/application.js:967:34)
at Object.<anonymous> (http://localhost:7165/public/application.js:980:6)
at mightThrow (http://localhost:7165/public/vendor.js:11500:30)
at process (http://localhost:7165/public/vendor.js:11568:13) undefined
so it worked, the record in question was deleted properly, but that jquery deferred exception now shows in the console, is that something I should worry about?
Looks to me like the issue is coming from onRemoveExerciseClick
. Do you need onShowAllExercisesSubmit()
to be part of that .then
statement?
ya that's what refreshes the list. As of right now , you can delete an exercise after ' show all exercises' but if you add an exercise then delete it , the 'remove exercise' button doesn't work. There's also the jquery deferred exception issue too.
I removed this const data = getFormFields(event.target)
from the onShowAllExercisesSubmit
function, turns out I didn't need to pass 'data' to my api through that function. but I've got a new issue now. Thanks Ben!
User clicks the 'remove exercise' button next to an exercise record. Previously, I had required the user to manually enter an id of the record that they would like deleted from their list. I don't want the user to have to do that. The record of an exercise with the 'remove exercise' button placed next to it should be deleted when the button is pressed. So, thanks to plenty of help, we got the click handler to listen properly (https://github.com/ga-wdi-boston/full-stack-project/issues/1021). Now I have a new error:
Uncaught TypeError: Cannot read property 'id' of undefined
stemming from my api, 'data.exercises.id
'. 'id' is undefined because we deleted it? I checked my exercises TABLE, the id still exists.The api request previously worked while expecting 'data' which comes from
getFormFields
in myonRemoveExerciseClick
function. Now to get the event listener to work from my previous issue we had to change data toconst id = $(event.target).attr('data-id')
. I tried renaming 'data' to 'id' and that didn't work.