Home > OS >  ASP Classic include file using AJAX
ASP Classic include file using AJAX

Time:06-03

I have a Bootstrap nav and I would like to change de content of the #result div using the Include.File from ASP Classic on click. Is there a way to do this?

HTML

<body onl oad="">
    <nav >
         span><%=rs(2)%></span>
                
         <ul >
              <li >
                  <a  style="cursor: pointer;" id="solicitar" onclick="test('solicitar.asp')">Solicitar</a>
              </li>
              <li >
                  <a  style="cursor: pointer;" id="consultar" onclick="test('consultar.asp')">Consultar</a>
              </li>
         </ul>

         <a  href="">
             <img src="../imgs/logos/4_COL-1.jpg" width="200" height="50"  alt="">
         </a>

         <span><%=date%></span>
   </nav>

   <div  id="result">
                
   </div>
</body>

JavaScript

function test(fileName) {
  $.ajax({
    method: "POST",
    data: {},
    success: function () {
      $("#result").html('<!--#Include File="'   fileName   '"-->');
    },
    error: function (x) {
      console.log(x);
    },
  });
}

CodePudding user response:

To request a page via ajax you set the url parameter to the address of the page.
If successful you will get the page contents in the success function.
Used GET instead of POST since it was just a page request.

function test(fileName) {
  $.ajax({
    url: fileName,
    method: "GET",
    success: function (html) {
      $("#result").html(html);
    },
    error: function (x) {
      console.log(x);
    },
  });
}
  • Related