Reputation: 1596
How can I successfully use this variable within the the appended message of the AJAX success call?
http://codepen.io/anon/pen/fdBvn
data['name'] = $('#goofy').val();
$.ajax({
url: '/api/1/email/test/',
data: data,
type: 'POST',
error: function(){
alert("Sorry, error with our server, we're working on it now");
},
success: function(){
$('#success').append('<h2>Thanks "+data['name']+"!</h2><p>We will be in touch shortly</p>');
}
});
Upvotes: 0
Views: 329
Reputation: 68400
You have to use proper quoting.
$('#success')
.append('<h2>Thanks '+data['name']+'!</h2><p>We will be in touch shortly</p>');
Notice that in your code you're opening your string with '
but closing it with "
Upvotes: 1