Is there any way to wait for AJAX response and halt execution?

前端 未结 6 983
囚心锁ツ
囚心锁ツ 2020-12-24 10:42

Here is some code I\'d like to execute. I\'d like to wait for AJAX response so I can return something from the server. Any way to achieve this?

function func         


        
6条回答
  •  感动是毒
    2020-12-24 11:26

    There is no need to wait for an Ajax-response. You can load your data in the head-section of your application:

    function functABC(){
        $.ajax({
            url: 'myPage.php',
            data: {id: id},
            success: function(data) {
                sessionStorage.setItem('mydata', data);
            }
        });
    } 
    

    Then when the window.load event has fired, your data will be available:

    alert(sessionStorage.getItem('mydata'));
    

提交回复
热议问题