Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript/ajax display to html issue

Status
Not open for further replies.

jgraves13

Programmer
Jan 31, 2007
42
US
I have an html file that calls a javascript/AJAX file which calls an ASP page. the ASP only generates the current year, then returns it to AJAX, then this should return it to the html page... and it's not... can some see what it is I am doing wrong? When I put the javascript/ajax in the actual html code it works... however for the application I am building this is NOT an option that is available to me

html file:
Code:
<head>
    <title>Copyright Year Example AJAX</title>
    <script type="text/javascript" src="CopyrightYear.js"></script>
</head>
<body onload="ajaxFunction()">
 1997-<div id="CopyrightYearid" /> <br />
 1997-<span id= "CopyrightYearid" /> <br />
</body>
</html>

ajax file:
Code:
// JScript File
<script type="text/javascript">

function ajaxFunction()
{
 var xmlHttp;

 try
 {
  xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
 }
  catch (e)
  {
    // Internet Explorer
    try
    {
     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
     catch (e)
     {
       try
       {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (e)
       {
         alert("Your browser does not support AJAX!");
         return false;
       }
     }
  }

  xmlHttp.onreadystatechange=function()
  {
   if(xmlHttp.readyState==4)
   {
    document.CopyrightYearid.value=xmlHttp.responseText;
    CopyrightYearid.value=xmlHttp.responseText;
    //document.myForm.CopyrightYearid.value=xmlHttp.responseText;
   }
  }
  xmlHttp.open("GET","CopyrightYear.asp",true);
  xmlHttp.send(null);
}
</script>

 
Take out the script tag lines in the "aj**" file. (It is a javascript file, and I don't know why you call everything aj**.)
 
Try this, I think this is your problem. Add new to the function call.
Code:
  xmlHttp.onreadystatechange=[!]new[/!] function()
  {
   if(xmlHttp.readyState==4)
   {
    document.CopyrightYearid.value=xmlHttp.responseText;
    CopyrightYearid.value=xmlHttp.responseText;
    //document.myForm.CopyrightYearid.value=xmlHttp.responseText;
   }
  }
  xmlHttp.open("GET","CopyrightYear.asp",true);
  xmlHttp.send(null);
}

[monkey][snake] <.
 
I see tsuji, I wasn't understanding the entire question.

What is marked 'ajax file:' I thought was a snippet and just labeled incorrectly.

I didn't understand your reply either until I looked closely at it.

tsuji is correct.

Not understanding why you ** out aj[!]**[/!] though.

[monkey][snake] <.
 
monksnake and tsuji

First since ajax is javascript I have to leave the script tag in there the way it is... in order for it to work.

Next, that did not to make a difference whether I put new in or now... script 1 still works and script 2 does not.

~ JG
 
jgraves, you will call that js file externally. External javascript files do NOT have the script tag in them, if they do, they won't work.

About adding "new", that was a stab before I really understood your question, I apologize for that.

[monkey][snake] <.
 
Sorry... I am a bonehead... I now understand what you were talking about.... I did remove the script tag still no luck... but I have an idea now...

~JG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top