lrony* 2014-02-20 09:09 采纳率: 0%
浏览 95

Ajax导致alert()[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
                            <span class="question-originals-answer-count">
                                (38 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2014-02-20 11:58:24Z" class="relativetime">6 years ago</span>.</div>
        </div>
    </aside>

How can I get imageX show it's value when used outside of $.ajax()?

var imageX;
$.ajax({
    type: 'GET',
    url: 'php/my1.php',
    dataType: 'json',
    async: 'false',
    success: function(response){
        imageX = response[0].studentName,
        groupX = response[0].subjectId;
    }
});
alert(imageX);
</div>
  • 写回答

3条回答 默认 最新

  • Didn"t forge 2014-02-20 09:10
    关注

    Change

    async: 'false',

    to

    async: false,

    'false' is string which is cast to true by Jquery(JS).

    Jquery Ajax Documentation says async accept boolean value.

    async (default: true): Type: Boolean By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false.

    https://api.jquery.com/jQuery.ajax/

    async:false will cause the jQuery.ajax() call to block until it returns. instead of this:

    function your ajax_calling_function
        call your ajax 
        callback with results
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧