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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting an html file inside div tags

Status
Not open for further replies.

lwfg

Programmer
Feb 9, 2009
52
US
Trying to put an html file in div tags. It works if I use method get but want post. It also works if the extension of the filename "fn" that goes to f() is cfm instead of html.
What am I doing wrong?

This is the dtry.html that sets up the screen and tries to put dtry1.html (further down) into the div area "content".

Code:
<html>
   <head>
      <title>
      </title>
      <script type="text/javascript">
         function f(fn,dn)
         {
            var req=false;
            if (window.XMLHttpRequest)
               req=new XMLHttpRequest()
            else
               if (window.ActiveXObject)
                  req=new ActiveXObject("Microsoft.XMLHTTP");
            if (req)
            {
               req.open("POST",fn,true);
               req.setRequestHeader("Content-type","application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
               req.onreadystatechange=function()
                                      {
                                         if (req.readyState==4 && req.status==200)
                                         {
                                            document.getElementById(dn).innerHTML=req.responseText;
                                            delete req;
                                            req=null
                                         }
                                      };
               req.send()
            }
            else
            {
               alert('No req.');
               return false
            };
         }
         function aa()
         {
            alert('*')
         }
      </script>
      /*style sheet part goes here*/
   </head>
   <body>
      <div id="outer">
         <div id="header1">
         </div>
         <div id="header2">
         </div>
         <div id="sider">
            <a href="#" id="a2" onclick="f('dtry1.html','content');">
               click
            </a>
         </div>
         <div id="content">
            Content
         </div>
         <div id="footer">
            Footer
         </div>
      </div>
   </body>
</html>
Below is dtry1.html I want inside the div "content" is here.

Code:
<html>
   <head>
      <title>
      </title>
   </head>
   <body>
      <a href="#" id="aa" onclick="aa();"> /*works if aa() in file with f()*/
         click
      </a>
      <form>
         <input name="bb" type="submit" value="click" onclick="f('dtry2.html','content');">
      </form>
   </body>
</html>
 
is cfm instead of html.

Maybe because it is coming from a ColdFusion server??


Is the server set to deliver content using POST?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I think it's set to deliver content with POST since on that server I use method POST with ColdFusion and the script above, f(), with img tags around req.responseText, can display a picture with POST.
 
I think it's set to work with POST since that's what I use with ColdFusion and since in the script above, f(), when req.responseText's value is the name of an image file and content's innerHTML is set to '<img src='+req.responseText+'>', the picture displays. In f(), the html file will show when GET is used instead of POST.
 
Is there an html file with that name in the same path as the base file that's trying to load it?

Usually Ajax is not used to load static html pages, and your server may be preventing this, but that would be a server config.

Have you tried alerting what if anything the ajax call is returning?

Code:
if (req.readyState==4 && req.status==200)
                                         {
[b]alert($req.responseText);[/b]
                                            document.getElementById(dn).innerHTML=req.responseText;
                                            delete req;
                                            req=null
                                         }


Also have you checked for any errors in the JS console? Most browsers have one of these.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Yes, there is a file with that name.
When fn is html, responseText is an error message "the HTTP verb used to access this page is not allowed" and status=405.
Sorry didn't check this earlier.

 
Seems POSTING to a static HTML page is not allowed in your setup.

What happens if you change the method to GET instead? Since its HTML, it won't matter as you aren't really passing any values to it to be processed. so you just want to get the page rather than post values to it.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
It works with GET. Later I want to send values. Maybe best to use cfm for that?
 
Yes. If you want to send values, then a static HTML page will do nothing with them. You would need a server side script that can access the values and do something with them. HTML cannot do that. So when you deicde to send values you would need a CFM script that can process the posted values.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
You can use GET on a static HTML page and use JS to read the QS values. Though if you load the page via AJAX this may not be possible. It also isn't a nice way to process GET parameters.

As Phil states POST will not work on a static HTML page.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top