0

Hi i am facing a problem here while loading dynamic content in multiple dropdown using $(window).on("load", function(){}) in chrome it is working fine but in safari i am unable to get the dynamic content in dropdown none of them working below is my code

$(window).on("load", countryLoad);
function countryLoad() {

var urlink = " http://xxx.xxx.x.xx/Service1.svc/getCou";
$.ajax({
    type: 'GET',
    url: urlink,
    success: function (resp) {
        var select = document.getElementById("dpdclt");
        var data = "";


        document.getElementById("dpdclt").options.length = 0;
        $("#dpdclt").append($("<option></option>").val(0).html('Select Country'));
        for (var i = 0; i < resp.length; i++) {

            $("#dpdclt").append($("<option></option>").val(resp[i].Sno).html(resp[i].Country));
        }



    },
    error: function (e) {

        window.plugins.toast.showLongBottom("Check your connection settings");

    }
});};

like the above function i have 6 other functions which i have to load on page load

  1. $(window).on("load",function2);
  2. $(window).on("load",function3);
  3. $(window).on("load", function4);
  4. $(window).on("load", function5);

Here when the page loads in the dropdown im getting only 'Select Country' in the dropdown it is not loading dynamic contents

Curiousdev
  • 5,668
  • 3
  • 24
  • 38
Madpop
  • 729
  • 4
  • 24
  • 61

1 Answers1

0

Usually you can use window.onload, but you may notice that recent browsers don't fire window.onload when you use the back/forward history buttons.

You can try one of the below code if you want to execute something on page load.

$(document).ready(function(){
    //Page loaded
});

OR

$(function(){
    //Page loaded
});

EDIT: Try this

window.onload = function(){
   //Page loaded
};

Or if you want to use jQuery then try this

$(window).bind('load', function(){
   //Page loaded
});

Still facing error check your console for any errors...

Curiousdev
  • 5,668
  • 3
  • 24
  • 38
  • The $(document).ready(function(){ //Page loaded }); solution worked.. – Madpop May 12 '17 at 12:03
  • that's great :) – Curiousdev May 12 '17 at 18:04
  • `jQuery.bind()` is deprecated... don't use it, use `.on()` instead. Don't set `window.onload`... it's a bad way to set event handlers as there can only be one. -1 for also not explaining the differences between `document.ready` and `window.onload`. – Brad May 14 '17 at 05:07
  • @Brad yes Ur completely right but OP didn't mentioned which jQuery version is using and that's the reason I have added all the possible solutions.. thanx for -1 ;) there are many articles available though to finding out difference so as per my thoughts I don't think I need to write all explanation here OP is enough capable to find out – Curiousdev May 14 '17 at 06:36