0

在执行用户登录时,如果登录成功,我想在某个div中显示一条消息。但是,如果登录失败,则会在另一个 div 中显示另一条消息。是否可以确定 Ajax 的“returnData”的内容并相应地更新适当的 div?例如:

$(document).ready(function() {
  $('.submitForm').ajaxForm({
    success: function(returnData) {
      if (returnData == '...') { // (or: len(returnData) == ... whatever)
          $('#someDiv').html(returnData);
      } else {
          $('#otherDiv').html(returnData);
      }
    }
  });
});
4

2 回答 2

0

当然。当然,返回数据必须支持传回登录请求的成功或失败。在这种假设下,您的代码看起来很正确。你试过了吗?

于 2012-12-26T03:23:21.173 回答
0

是的,当然可以这样做。您正在使用伪代码:

if returnData == '...'
    $('#someDiv').html(returnData);
else
    $('#otherDiv').html(returnData);

但实际上并不遥远:

if(returnData == '...')  // note the parentheses
    $('#someDiv').html(returnData);
else
    $('#otherDiv').html(returnData);
于 2012-12-26T03:23:27.430 回答