如何在$ .post jQuery中等待响应 [英] How to wait for response in $.post jQuery

查看:619
本文介绍了如何在$ .post jQuery中等待响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP以1-2秒的延迟返回值jQuery.post不等待响应.

PHP returns value with 1-2 second delay jQuery.post doesn't wait for response.

您如何看待,是否有可能解决该问题并等待响应?

How do you think, is it possible to fix that problem and wait for response?

    $.post( sSource, aoData, function (data) {    
        oCache.lastJson = jQuery.extend(true, {}, data);
        if ( oCache.iCacheLower != oCache.iDisplayStart )
        {
            data.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
        }
        data.aaData.splice( oCache.iDisplayLength, data.aaData.length );
         abc(oCache);
        fnCallback(data); 
    },"json" );

注意与get相同的功能效果很好

Note the same function with get works well

    $.getJSON( sSource, aoData, function (json) { 
        /* Callback processing */
        oCache.lastJson = jQuery.extend(true, {}, json);

        if ( oCache.iCacheLower != oCache.iDisplayStart )
        {
            json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
        }
        json.aaData.splice( oCache.iDisplayLength, json.aaData.length );

        fnCallback(json)
    } );

推荐答案

$.post是异步的,您需要使用$ .ajax并将async设置为false,这样您就可以等待响应. 您可以在此处了解更多信息: http://api.jquery.com/jQuery.ajax/

$.post is asynchronous, you need to use $.ajax and set async to false, that way you will be able to wait for the response. You can read more about it here: http://api.jquery.com/jQuery.ajax/

这篇关于如何在$ .post jQuery中等待响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆