AJAX responseText issue

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

The issue is this...when I set the innerHTML equal to my AJAX responseText...for some reason I end up getting my header returned to the innerHTML...I don't want the header I want the list generated by my recentview_manager.asp

Any thoughts?

HERE'S the relevant JS
Code: [ Select ]
<script type="text/javascript">        
        var xmlhttp
        function manageRecentView(transaction)
        {
            xmlhttp=GetXmlHttpObject();
            if (xmlhttp==null)
            {
                alert ("Your browser does not support AJAX!");
                return;
            }
            var url="recentview_manager.asp?trx=" + transaction;
            xmlhttp.onreadystatechange=stateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        }
        
        function GetXmlHttpObject()
        {
            if (window.XMLHttpRequest)
            {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                return new XMLHttpRequest();
            }
            if (window.ActiveXObject)
            {
                // code for IE6, IE5
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
        return null;
        }
        
        function stateChanged()
        {
            if (xmlhttp.readyState==4)
            {
                //TIME TO REGET RECENTVIEW        
                document.getElementById("recentViewed").innerHTML=xmlhttp.responseText;
            }
        }     
    </script>
  1. <script type="text/javascript">        
  2.         var xmlhttp
  3.         function manageRecentView(transaction)
  4.         {
  5.             xmlhttp=GetXmlHttpObject();
  6.             if (xmlhttp==null)
  7.             {
  8.                 alert ("Your browser does not support AJAX!");
  9.                 return;
  10.             }
  11.             var url="recentview_manager.asp?trx=" + transaction;
  12.             xmlhttp.onreadystatechange=stateChanged;
  13.             xmlhttp.open("GET",url,true);
  14.             xmlhttp.send(null);
  15.         }
  16.         
  17.         function GetXmlHttpObject()
  18.         {
  19.             if (window.XMLHttpRequest)
  20.             {
  21.                 // code for IE7+, Firefox, Chrome, Opera, Safari
  22.                 return new XMLHttpRequest();
  23.             }
  24.             if (window.ActiveXObject)
  25.             {
  26.                 // code for IE6, IE5
  27.                 return new ActiveXObject("Microsoft.XMLHTTP");
  28.             }
  29.         return null;
  30.         }
  31.         
  32.         function stateChanged()
  33.         {
  34.             if (xmlhttp.readyState==4)
  35.             {
  36.                 //TIME TO REGET RECENTVIEW        
  37.                 document.getElementById("recentViewed").innerHTML=xmlhttp.responseText;
  38.             }
  39.         }     
  40.     </script>


HERE'S recentview_manager.asp
Code: [ Select ]

    select case request.querystring("trx")
        case "get"
            recent = getRecent()
            str=""
            for a = 0 to ubound(recent)    
                work = split(recent(a), chr(252))     
                str = str & "<li><a href='" & basepath & "" & work(0) & "' name='recentview'>" & work(1)& "</a></li>"
            next
            if ubound(recent) > 0 then
                str = str & "<li style='text-align:center;'><a href=""javascript&#058;manageRecentView('remove')"" style='font-size:10px;'>Reset List</a></li>"
            end if
            response.write(str)
        case "remove"
            removeRecent()
            response.write("")
    end select
  1.     select case request.querystring("trx")
  2.         case "get"
  3.             recent = getRecent()
  4.             str=""
  5.             for a = 0 to ubound(recent)    
  6.                 work = split(recent(a), chr(252))     
  7.                 str = str & "<li><a href='" & basepath & "" & work(0) & "' name='recentview'>" & work(1)& "</a></li>"
  8.             next
  9.             if ubound(recent) > 0 then
  10.                 str = str & "<li style='text-align:center;'><a href=""javascript&#058;manageRecentView('remove')"" style='font-size:10px;'>Reset List</a></li>"
  11.             end if
  12.             response.write(str)
  13.         case "remove"
  14.             removeRecent()
  15.             response.write("")
  16.     end select
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

When I run recentview_manager.asp?trx=get directly in the browser...it's generating the list I want.

The problem must be somewhere on the requesting page where <div id="recentViewed"> lives...
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

It wasn't returning the header...it was returning my custom 404 page.

My path to "recentview_manager.asp" was incorrect.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Ahh, glad you got that. I scratched my head over it and recreated it trying to find the issue - the code you had was by the book, so I was confused. Good that you figured it out. ;)

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 65 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.