dongshan3806 2016-08-25 16:03 采纳率: 0%
浏览 131

Ajax异步调用true返回值

I need some help with ajax call, I have problem with async true. So I have form on html page and i am using ajax call to call me the php script that is sending the data to email and then it returns the value back to page and displays notification regarding the value returned. So far everything worked ok with this code:

$.validator.setDefaults( {
    submitHandler: function () {
        $.ajax({
            type: 'post',
            url: 'Link - script to send info and returns the value',
            data: $('form').serialize(),
            async: false,
            success: function (result) {
                if (result == '1') {
                    $("#error").hide();
                    $("#validate").hide();
                    $("#poslano").show();
                }else {
                    $("#error").show();
                }
            },
        });
    }
} );

So after all inputs are correct the form if submitted and this part of ajax script sends the data to script and get the returned value. But if I have async set to false I always get this error back even if form is correct:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

But if I set async to true, then nothing happens. I just get the error message. How should i resolve this problem ? Many thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanfei8149 2016-09-01 09:08
    关注

    Thanks for help.

    Resolved

    async: false;

    changed to

    async: true;

    and now it works no more errors in console.

    Thank you again.

    But if I use async: true; then the browser doesn't freeze if I am correct to wait for result, how should I handle result in that case? Whit event?

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算