English 中文(简体)
Ajax 调用 Ajax 调用未及时更新的变量
原标题:Variable not updated in time with Ajax call

我缩小了早先的问题的范围,我问了这个问题,并发现了什么是错的,但解决不了。

我有一个变量 需要设定在一个事件函数内 在下一个事件火灾之前

这不可能发生, 因为我通过 Ajax 呼叫检索变量 。 尽管我认为我所有的 ajax 设置都正确 (? ), 但事实并非如此 。 我在 Firebug 中使用控制台记录记录, 而其中有“ 2” 的控制台日志会在应首先生成的其他日志条目( 其中有“ 1 ” ) 之前登录 。

它是一个日期选手实例的一部分, 带有 ajax 调用。 下面是完整的代码。 顺便说一句, 我拿了 ajax 调用, 插入了一个硬码变量来测试它, 它非常有效。 所以它没有正确运行。

变量 volDate 在文档准备功能之外声明 :

<script type= text/javascript >
 var varDate =  toby ;
$(document).ready(function(){

和这里的主代码

$( .subject-date-pick ).datetimepicker({
    timeFormat:  hh:mm:ss ,
    startDate: 01/01/1996 ,
    clickInput:true,
    beforeShow: function(input,inst) {

        var source = $("#" + inst.id).attr( source );
        var source_id = $("#" + inst.id).attr( source_id );
        var thing = $.ajax({
            type:  GET , 
            url:  ajax_get_unavailable_dates.php ,
            dataType:  text ,
            async:  false ,
            global:  false ,
            data: {
                source_type: source,
                source_db_id: source_id
                  },
            success: function(msg) {


                console.log("1 - got the result");

                varDate = (msg)
            }
        });
        console.log("2个ajax完成 - 伐木控制台");     
        console.log("Post Ajax"+varDate);

    },

控制台在这里所做的是错误地首先记录变量( 第二记录事件), 然后再记录下一个日期选择器火灾事件 。 在此之后, 变量 IS 更新 - 以及随后在日期选择器字段上的点击将设置correct 变量 - 但是这太迟了, 也不好 。

所以:主控台结果:

申请Ajax电话

2个ajax完成 - 伐木控制台

阿贾克斯托比哨所

1 - 得到结果

.

有人帮忙吗?

最佳回答

我猜这是因为 freedom ===================================================================================================================================== ======================================================================================================== ================================================

再试一次 async: fraud; 表示 $.ajax ajax 选项。

问题回答

尝试 async: false 而不是 async: freed





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...