469,270 Members | 1,137 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Error: 'document.getElementById(...)' is null or not an object.

3
Hi
when i m trying to execute my ajax code using a link to display datas from another page named second.php.,
i got an error when the page loads in "ie"., which runs perfectly in firefox.,

here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. var i;
  4. function httprequest(i)
  5. {
  6.  
  7. var xmlhttp;
  8. try
  9. {
  10.  xmlhttp=new XMLHttpRequest();
  11. }
  12. catch(e)
  13. {
  14.   try
  15.   {
  16.   xmlhttp=new Activexobject("Msxml2.XMLHTTP");
  17.   }
  18.   catch(e)
  19.   { 
  20.     try
  21.     {
  22.     xmlhttp=new Activexobject("MICROSOFT.XMLHTTP")
  23.     }
  24.     catch(e)
  25.     {
  26.      alert("ur browser doesnot support Ajax");
  27.      return false;
  28.     }
  29.   }
  30.  
  31. }
  32. xmlhttp.onreadystatechange=function()
  33.  if(xmlhttp.readyState==4)
  34.  { 
  35.  
  36.    obj = document.getElementById( "idname" );
  37.  
  38.    obj.innerHTML = xmlhttp.responseText;
  39.    getBufferText();
  40.  
  41.  }
  42. }
  43.  
  44. xmlhttp.open("GET", "second.php?i="+i,true);
  45. xmlhttp.send(null);
  46. }
  47.  
  48. function call_sec(i)
  49. {
  50.  httprequest(i)
  51. }
  52. </script>
  53.  
Expand|Select|Wrap|Line Numbers
  1. <table id="idname">
  2.  
  3. .............
  4. first page contents
  5. .................
  6.  
  7. <a onclick="call_sec(<? echo $i;?>)">second</a></table>
  8.  


when the page loads i get an error "Error: 'document.getElementById(...)' is null or not an object"
but works well with firefox.,

could anyone help me.,
its very urgent.,

thanks
Mar 20 '08 #1
8 5302
gits
5,390 Expert Mod 4TB
you have a typo - use:

Expand|Select|Wrap|Line Numbers
  1. new ActiveXObject
  2.  
in your IE section for creating the request-object.

kind regards
Mar 20 '08 #2
vjayis
134 100+
you have a typo - use:

Expand|Select|Wrap|Line Numbers
  1. new ActiveXObject
  2.  
in your IE section for creating the request-object.

kind regards

Hi

tried doing with the changes above., but still didnt get rid of the problem.,

thanks
Mar 21 '08 #3
gits
5,390 Expert Mod 4TB
please try to use a div instead of a table first ...

kind regards
Mar 21 '08 #4
vjayis
134 100+
please try to use a div instead of a table first ...

kind regards
Hi

tried changing to <div > tag., but not yet got the solution., when the page loads., i get the same error.,

thanks
Mar 22 '08 #5
gits
5,390 Expert Mod 4TB
when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

kind regards
Mar 22 '08 #6
ananjy
3
when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

kind regards

Hi

No code is executed on onload of the page.,
The only script on my page is the javascript used for ajax.

I hav enabled script debugging in browser setting., and get tht error which displays in the aert 'document.getElementById('...'') is null or not an object.,

if i disable the script debugging
the page gets loaded well., and displays the result in the status bar as
"done, but with some errors on the page".,

here is my code again

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var id;
  3. var action;
  4.  
  5.  
  6. function ajaxFunction(id,action)
  7. {
  8.  
  9. var xmlHttp;
  10. try
  11.   {
  12.   // Firefox, Opera 8.0+, Safari
  13.   xmlHttp=new XMLHttpRequest();
  14.   }
  15. catch (e)
  16.   {
  17.   // Internet Explorer
  18.   try
  19.     {
  20.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  21.     }
  22.   catch (e)
  23.     {
  24.     try
  25.       {
  26.       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  27.       }
  28.     catch (e)
  29.       {
  30.       alert("Your browser does not support AJAX!");
  31.       return false;
  32.       }
  33.     }
  34.   }
  35.  
  36. xmlHttp.onreadystatechange=function()
  37.  if(xmlHttp.readyState==4)
  38.  { 
  39.  
  40.    document.getElementById("ajax").innerHTML=xmlHttp.responseText;
  41.  }
  42. }
  43.  
  44. xmlHttp.open("GET","ajax.php?id="+id+"&action="+action,true);
  45. xmlHttp.send(null);
  46.  
  47. }
  48.  
  49. function hidden(id,action)
  50. {
  51.  ajaxFunction(id,action)
  52. }
  53.  
  54. </script>
  55.  

kind regards
vijay
Mar 26 '08 #7
gits
5,390 Expert Mod 4TB
the only part i could see where the error could come from is here:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("ajax")
do you have a node with id = 'ajax' in your document? ...

kind regards
Mar 26 '08 #8
ananjy
3
the only part i could see where the error could come from is here:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("ajax")
do you have a node with id = 'ajax' in your document? ...

kind regards



Hi got solution for the error,
i just simply added an if condition before tht line and got the solution.,
and thanks for tht.,

but after the page gets loaded.,
it displays the message in status bar as.,
"Done, but with some errors on page."

what might be the error???

how can i get an solution for this.,

regards
Mar 27 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by dubing | last post: by
1 post views Thread by Andrew Phillipo | last post: by
11 posts views Thread by westplastic | last post: by
8 posts views Thread by ipy2006 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.