Issue with multiple simultaneous Ajax Requests
Hello,
I'm trying to load html into the div's (which ever is empty) but the following code fails to work properly. Instead, it loads html in the same (div1) everytime, overriding previously loaded html.
- <div id="Div1" Class="col-sm-3 hidden"></div>
- <div id="Div2" Class="col-sm-3 hidden"></div>
- <div id="Div3" Class="col-sm-3 hidden"></div>
- $.each(chkUnivIDs, function (index, value) {
- DisplayUnivInfo(univID);
- });
- var univID;
- function DisplayUnivInfo(tID) {
- var chkDiv = ""; univID=tID;
- if ($('#Div1').html() == "" && chkDiv == "") {
- DisplayIn($("#Div1"));
- $('#Div1').removeClass('hidden');
- chkDiv = "Not Empty";
- }
- else if ($('#Div2').html() == "" && chkDiv == "") {
- DisplayIn($("#Div2"));
- $('#Div2').removeClass('hidden');
- chkDiv = "Not Empty";
- }
- else if ($('#Div3').html() == "" && chkDiv == "") {
- DisplayIn($("#Div3"));
- $('#Div3').removeClass('hidden');
- chkDiv = "Not Empty";
- }
- }
- function DisplayIn(ele1) {
- $.ajax({
- url: '@Url.Action("Action", "Controller")',
- cache: false,
- async: false,
- data: { id: univID},
- success: function (r) {
- $(ele1).html(r);
- //$(ele1).append(r);
- },
- error: function (r) {
- alert("Ajax Error: failed to load");
- }
- });
- }