0

I have control that I render throw ajax and append it to div in the document:

function RevrievePopUpViaAjax(url) {
     if (document.getElementById('abcd') == null) {
         var jqxhr = $.ajax({
             url: url,
             type: "GET"
         })
         .done(function (data) {
             $("#contentDiv").append(data);

         })
         .fail(function () {
             alert("error");
         })
     }
     else {
         abcd.PerformCallback();
     }
}

This is my original function in the first time I call it, it renders control with id 'abcd' when I call it the second time there is a difference between document.getElementById('abcd') that return null and shows like the element doesn't exists although it is really do exist to window.abcd that not return null and shows that the element do exists...

It probably my misunderstand of something... someone can explain it to me?

ilay zeidman
  • 2,654
  • 5
  • 23
  • 45
  • 6
    Can you show exactly how you are using `document.getElementById('abcd')` vs `window.abcd` within your code? it's all about context/timing. And what the actual id is. – Kevin B Feb 10 '14 at 18:53
  • 1
    And if you're using jQuery, why are you even bothering with `document.getElementById()`? You can just use `$("#myID")`... Also, consider using `$.get(url, function(data){ ...})`. – royhowie Feb 10 '14 at 18:54
  • @Luxelin I tried it and it is also not working... – ilay zeidman Feb 10 '14 at 18:56
  • @KevinB I will now update to my original code – ilay zeidman Feb 10 '14 at 18:56
  • the logic there doesn't make sense... Your first conditional tests to see if an element exists. If it doesn't exist, you're... using `abcd.PerformCallback()`... that's VERY confusing... What is `abcd.PerformCallback`? – Kevin B Feb 10 '14 at 19:03
  • why I am asking if it not exists...(document.getElementById('abcd') == null) then I render it with ajax and if it do exist I make callback... – ilay zeidman Feb 10 '14 at 19:04
  • I see. still. What is `adbc.PerformCallback`? are you really adding properties to dom elements? Why? – Kevin B Feb 10 '14 at 19:05
  • PerformCallback() is a function that abcd has... – ilay zeidman Feb 10 '14 at 19:06
  • well i can tell that much... but why does it exist? What do you mean by *"there is a difference between document.getElementById('abcd') to window.abcd"*? I don't quite understand what you are asking. It's unclear what the problem/mystery you are trying to solve is. – Kevin B Feb 10 '14 at 19:07
  • I edit it my question hope it is more clear now... – ilay zeidman Feb 10 '14 at 19:10
  • What does `console.log(abcd)` show you, and how are you defining `PerformCallback()`? – Jason P Feb 10 '14 at 19:14

0 Answers0