How to make an AJAX request on page load

前端 未结 7 1442
耶瑟儿~
耶瑟儿~ 2021-01-28 01:47

I need to call GetAllProperties() function during page loading instead of calling the GetAllProperties() function after page is fully loaded. My code l

7条回答
  •  心在旅途
    2021-01-28 02:23

    Replace

    $(document).ready(function () {   
            GetAllProperties();    
    });
    

    with just calling GetAllProperties(). you don't need DOM for ajax calls

    Then replace

    $("#MyDiv").empty();
    $("#MyDiv").append($data);
    

    with

    $(document).ready(function () {   
        $("#MyDiv").empty();
        $("#MyDiv").append($data);
    });
    

    Operate with DOM when it's ready. Other actions you can do without DOM.

提交回复
热议问题