Link to home
Start Free TrialLog in
Avatar of slightlyoff
slightlyoff

asked on

AJAX getting wrong page?

I've never head of this happening before - I'm not quite sure exactly what is going on.  Unfortunately the page this is occurring on is an "Admin" page - and I can't provide a useful link for you to see the behavior.  I'll do my best to describe it.

I have a page that allows the user to put online items that are in stock.  When a user enters a SKU, using AJAX, i return a HTML form  generated and filled in from the DB by "hrgetSku.asp".  The user can also click on a list of products already in the "in-stock" list by clicking a link in a list.

My XML Code looks like this (it's old code, been working for the past several years...):

<script type="text/javascript">
function getBP()
{

var xmlhttp;
var sku;

sku = document.getElementById('theSKU').value;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","hrgetSku.asp?sku="+sku,true);
xmlhttp.send();

return false;
}

function getEBP(aSku)
{

var xmlhttp;
var sku;

sku = aSku;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
//alert("here!");
xmlhttp.open("GET","hrgetSku.asp?sku="+sku,true);
xmlhttp.send();

return false;
}

Open in new window


When you click a link, you call the function like this:  <a onclick="getEBP('x4tte'); return false;" href="#">View x4tte</a>

You'll notice at the end of the getEBP() function there's an "alert('here')" commented out for testing purposes.
When I run my code (and the alert is uncommented out) - every link I click on works - I get the alert.  HOWEVER....

Some products seem to be pulling from an old or different "hrgetSku.asp" page.  I've made changes to "hrgetSku.asp" posted it, and for some products I see the change and for others i don't see the change.  As I mentioned earlier, "hrgetSKU.asp" returns a form that is filled in with the database.  To make sure the right page was getting called, I changed some titles on the form.  On most products the changes show up. On some, however, they don't - even though they are running through the same ajax and calling the same page.  Further - those products that don't show up don't pull all the data.  It's as if they are pulling a different hrgetSKU.asp page all together.  They are pulling some version of it, because it looks identical, minus my changes and missing data.

So this is very strange...  I even added the full "http://www.mywebsitehere.com/admin/hrgetSKU.asp" path to the hrgetSKU.asp page in my ajax code.  It still doesn't pull the file  with my changes.  I think Im going mad...

This is a difficult question to ask since I can't show you the behavior, but  I hope I've made clear what's going on.
Any help would be greatly appreciated!!!
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, all the browsers have a console feature.  https://developer.chrome.com/devtools/docs/console  In chrome, if you run your page with the console open, you can look at what is going on with the ajax page, what data is being sent and what is being returned.  To see this info, click on the Network tab and find the ajax page, then click on it. Then on the right there will be some options to see the request and response.

Try and run the page directly as well from a url.
There's no reason to put your Ajax pages in a separate folder other then organizational reasons for yourself. A url is a url is a url.

As for a random number vs using a date, chances of repeating a random number twice in a row (and therefore caching the url) is so unlikely to happen it's not something to worry about until you figure out the cause of your issue. I've used both methods throughout the year and never into any caching problems.
Avatar of slightlyoff
slightlyoff

ASKER

Thanks all for the responses. I'm just getting back into the office today and will look into it more.
I really appreciate the help!
Thanks for your help on this.
I came in this morning, and everything worked as it was supposed to - before I put the random number on.
I assume that's because over the weekend something refreshed on the server.  So I think you're right, it's a caching issue.

I've added the random numbers and tested it.  I'll have to wait and see if it happens again.

Thanks for your help!  I was worried it was such a weird question that no one would answer.
Big Monty - Different folders are not just for keeping things organized. https://support.microsoft.com/en-us/kb/290591NOTE: The two ASPs should be in different virtual folders due to threading issues..  That type of note is on many xmlhttp help files.  I have always used that for both server side and client side ajax.  

As for randomness, check out the collisions http://jsbin.com/movuje/1/edit?html,output. If it takes the same effort to just use the time which will not be duplicated, why wouldn't you use it?
interesting article, but it looks to be discussing Windows 2000.

do you have any documentation for newer versions of IIS, as I would be curious about it...
It's always been that way for classic asp as far as I can remember.  It can still physically work in the same folder, but when I have had issues this is what it always came back to and of course with client side generating a unique something to add to the url.