How to force a program to wait until an HTTP request is finished in JavaScript?

前端 未结 6 453
孤城傲影
孤城傲影 2020-12-25 12:41

Is there a way in JavaScript to send an HTTP request to an HTTP server and wait until the server responds with a reply? I want my program to wait until the server replies an

6条回答
  •  青春惊慌失措
    2020-12-25 13:14

    You can perform a synchronous request. jQuery example:

    $(function() {
        $.ajax({
           async: false,
           // other parameters
        });
    });
    

    You should take a look at jQuery's AJAX API. I highly recommend using a framework like jQuery for this stuff. Manually doing cross-browser ajax is a real pain!

提交回复
热议问题