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!!!
LVL 1
slightlyoffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
there could be an issue with caching that's occurring, to avoid any caching issues, you need to send an original url everytime. The best way to achieve this is to add another querystring parameter that contains a random value:

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

can be changed to:
var randNum = Math.round(Math.random()*10000);
xmlhttp.open("GET","hrgetSku.asp?sku="+sku + "&r=" + randNum,true);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Placing a unique url as big montey shows is one thing but your ajax pages should also be in a different folder.

The only thing I would suggest to change for the url is not use a random number because randomness does not mean uniqueness.  

var dt = Date.now();
xmlhttp.open("GET","another_folder/hrgetSku.asp?sku="+sku + "&r=" + dt,true);
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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.
0
slightlyoffAuthor Commented:
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!
0
slightlyoffAuthor Commented:
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.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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...
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.