[英]Append a variable from within an AJAX success call
How can I successfully use this variable within the the appended message of the AJAX success call? 如何在AJAX成功调用的附加消息中成功使用此变量?
http://codepen.io/anon/pen/fdBvn 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>');
}
});
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 "
请注意,在您的代码中,您使用
'
打开字符串,而使用"
关闭"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.