Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTimo Bontenbal
9,582 PointsJquery Ajax Error: Uncaught ReferenceError: success is not defined
Hi,
I am trying to get Form data to a php file. Jquery does get the element but somehow it get this error message: Uncaught ReferenceError: success is not defined.
My code:
$(document).ready(function() {
$('form.palkkaLaskuri').on('submit', function(event){
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response){
console.log(success);
}
});
event.preventDefault();
});
});
2 Answers
Jose Ortiz
Courses Plus Student 6,161 Pointsin console.log you calling success which would.be seen as a undeclared variable
Jonas Olausson
9,161 PointsThat's because the callback that you get from the success function is named response in your code. Try using console.log on response instead.
//Jonas
success: function(response){
console.log(response);
}