簡體   English   中英

從AJAX成功調用中追加變量

[英]Append a variable from within an AJAX success call

如何在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>');
}
});

您必須使用正確的引用。

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

請注意,在您的代碼中,您使用'打開字符串,而使用"關閉"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM