我有一个 AJAX 注册表:
var id = null;
$.ajax({
type: 'POST',
url: requestUrl,
data: $(".defaultRequest").serialize(),
dataType: 'json',
success: function(data) {
if(data.response){
$('div.errormsg').remove();
if(data.step){
openStep(data.step);
}else{
openStep('next');
}
}else{
$('div.errormsg').remove();
$('<div class="errormsg">'+data.message+"</div>").insertBefore(form);
}
}
});
当用户注册成功后,我想向他显示他的唯一ID,但它保持为NULL。怎么解决呢?
<script type="text/javascript">
$('#linkkk').text('Your id is: '+id+'');
</script>
最佳答案
您需要在成功回调中先设置id。
$.ajax({
type: 'POST',
url: requestUrl,
data: $(".defaultRequest").serialize(),
dataType: 'json',
success: function(data) {
if(data.response){
$('div.errormsg').remove();
if (data.step) {
openStep(data.step);
} else {
openStep('next');
}
$('#linkkk').text('Your id is: ' + data.id);
} else {
$('div.errormsg').remove();
$('<div class="errormsg">'+data.message+"</div>").insertBefore(form);
}
}
});
关于javascript - jQuery var 没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17060495/