0

如何在 AJAX 成功调用的附加消息中成功使用此变量?

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>');
}
});
4

1 回答 1

1

你必须使用正确的引用。

$('#success')
  .append('<h2>Thanks '+data['name']+'!</h2><p>We will be in touch shortly</p>');

请注意,在您的代码中,您打开字符串'但使用关闭它"

于 2013-06-26T15:02:30.250 回答