为什么这两个变量会返回不同的结果?

时间:2017-04-18 14:24:17

标签: javascript jquery

$(".chat-b").each(function(){ 
    other_user = $(this).attr("ref");

var check_for_new = (
    typeof asynco_dt === "object" 
    && asynco_dt.new_messages > 0) ? {
            "action":"chat_with_user","user":other_user,"new_only":true
        }:{
            "action":"chat_with_user","user":other_user
        };
    $.ajax({
        url:"<?php echo $main_dir; ?>core/simcheck.php",
        data:check_for_new,
        success:function(chat_sync){
             if(typeof messages_p === "string") {delete messages_p;}  //cringe. yep lol    
             num = chat_sync.messages.length - 1;
             x = chat_sync.messages[num].postid;   //get the postid of the very last post in a chat comment chain    
             y = (typeof $(".chat-b[ref='"+ check_for_new.user +"'] .spacer .chat_box p:last").attr("num") !== "string") ? 0 : $(".chat-b[ref='"+check_for_new.user+"'] .spacer .chat_box p:last").attr("num"); //just a quick fix for those pre-loaded chat boxes        
   if(typeof chat_sync.messages === "object" && x > y){ //inserting the chat box in}

为什么other_user变量在$.ajax函数范围内而不是check_for_new.user内有不同的返回结果,即使它们基于相同的变量,也有什么解释?我最初认为这是关于功能范围

为回答这个问题所需的上下文可能需要发布更多代码,我将自由发布

0 个答案:

没有答案