Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2012, 10:18 PM   PM User | #1
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Question AJAX calling seemingly random and nonexistent version of a PHP page.

I am using ajax to call a php page, do a mysql query and return a simple echo. But the strangest thing seems to happen. The ajax seems to call a previous versions of my PHP (ie, an older version with different code and echo statements in them). This happens randomly and only with some inputs over others. Also, the version of the PHP changes too! Sometimes it'll call one that existed yesterday, one that existed 3 days ago or one that existed an hour ago. None of them exist anymore. They've been overwritten.

I am thinking there might be temporary files in the same directory as the most current PHP file that ajax is confusing with. Is there any way to know with Filezilla?
The Noob Coder is offline   Reply With Quote
Old 08-07-2012, 10:37 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Can you show us some scripting?
No such thing as temporary files (that I know of).
mlseim is offline   Reply With Quote
Old 08-08-2012, 12:12 AM   PM User | #3
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Here's the JS that makes up the AJAX. There's virtually nothing in the PHP page, except for a few echoes. What happens is that I'll change what is being echoed and when the AJAX returns the echo string from PHP it'll be a string that was only in a previous version of the file.

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type='text/javascript' >

		var http;
		
		function setXMLHttpRequest()
		{
			if(window.XMLHttpRequest)
				http = new XMLHttpRequest();
			else if(window.ActiveXObject)
				http = new ActiveXObject("Microsoft.XMLHTTP");
				
				url = "http://www.convolutedconstruct.com/Ajax/checkemail6.php?email=" + document.getElementById('email').value;
				http.onreadystatechange = display;
				http.open("GET", url, true);
				http.send(null);
			
		}
		
		function display()
		{
			if (http.readyState == 4)
			{	
				infostr = http.responseText;
				alert(infostr);
				
				if(infostr == "true")
				{
					jQuery(document).ready( function() {
						jQuery("#emailForm").slideUp('slow');
						jQuery("#Image1").fadeIn(3500);
						
					});
				}
				else if(infostr == "invalid")
				{
					//Tell user they provided an invalid email address
					jQuery(document).ready( function() {
						jQuery("#invalidMessage").slideDown();
						
					});
				}
				else
				{
					//Email was valid but not in the database.
					jQuery(document).ready( function() {
						jQuery("#emailNotRecorded").slideDown();
						
					});
				}
			}
		}
});

</script>
You'll notice that the URL being called is checkemail6.php. So far renaming the PHP file after an edit and then FTPing it was the only way to solve the problem (or at least circumvent it). It's as if there are multiple different copies of the original checkemail.php file in the directory and the JS is conflicted as to which one to choose. Does that make sense?
The Noob Coder is offline   Reply With Quote
Old 08-08-2012, 01:28 AM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Try

Code:
var encmail = encodeURIComponent(document.getElementById('email').value);

url = "http://www.convolutedconstruct.com/Ajax/checkemail6.php?email=" + encmail;
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-08-2012, 09:01 PM   PM User | #5
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Quote:
Originally Posted by AndrewGSW View Post
Try

Code:
var encmail = encodeURIComponent(document.getElementById('email').value);

url = "http://www.convolutedconstruct.com/Ajax/checkemail6.php?email=" + encmail;
Before I put it into my code, could I trouble you to please explain what that first line does? Thank you.
The Noob Coder is offline   Reply With Quote
Old 08-08-2012, 09:05 PM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by The Noob Coder View Post
Before I put it into my code, could I trouble you to please explain what that first line does? Thank you.
It just creates a temporary variable to store the result after encoding the email text. Google encodeURIComponent.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-08-2012, 09:32 PM   PM User | #7
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
I added the encoded email, but it didn't work. It is calling and receiving data from an outdated version of the PHP file.
The Noob Coder is offline   Reply With Quote
Old 08-08-2012, 09:46 PM   PM User | #8
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Check the status as well:

Code:
alert(http.status);
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-08-2012, 09:47 PM   PM User | #9
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Where should this go?
The Noob Coder is offline   Reply With Quote
Old 08-09-2012, 03:03 AM   PM User | #10
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Since you are already including jQuery it's easier to do the AJAX with $.get():
Code:
(function($) {
    $(function() {

        var url = "http://www.convolutedconstruct.com/Ajax/checkemail6.php";
        var input = {email: $('#email').val()};
        $.get(url, input, function(data){
        
            infostr = $.trim(data);
        
            if(infostr == "true")
            {
                $("#emailForm").slideUp('slow');
                $("#Image1").fadeIn(3500);
            }
            else if(infostr == "invalid")
            {
                //Tell user they provided an invalid email address
                $("#invalidMessage").slideDown();
            }
            else
            {
                //Email was valid but not in the database.
                $("#emailNotRecorded").slideDown();
            }
        });

    });
})(jQuery);
Not tested, but you should get the idea. Also note that AJAX requests can be cached just like regular pages, so if you notice an issue with items being cached you can append a timestamp or random number to prevent the request from being cached.
Inigoesdr is offline   Reply With Quote
Old 08-09-2012, 05:30 AM   PM User | #11
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Caching . . . is that what's going on? So if I put a timestamp on the JS, will that affect the PHP, too? Is there a way to just clear the cache on the PHP?
The Noob Coder is offline   Reply With Quote
Old 08-09-2012, 05:28 PM   PM User | #12
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by The Noob Coder View Post
Is there a way to just clear the cache on the PHP?
Not exactly, but you can prevent it from being cached in the first place by sending expired cache header()s.
Inigoesdr is offline   Reply With Quote
Old 08-09-2012, 10:03 PM   PM User | #13
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
I added the header to disable the cached entries, but it still seems to call on previous versions of the file. I'll somethings and get back and let you know.
The Noob Coder is offline   Reply With Quote
Old 08-09-2012, 10:41 PM   PM User | #14
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Send a timestamp along with the the querystring request.
Caching can occur at many different steps, and may or may not be ignored by the device.
Fou-Lu is offline   Reply With Quote
Old 08-09-2012, 10:57 PM   PM User | #15
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Nevermind. It worked. I had another bug that was interfering with it. Thank you for your help.
The Noob Coder is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, nonexistent pages, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:08 AM.


Advertisement
Log in to turn off these ads.