SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    kill safari...KILL IT

    so as per my subject...I hate Safari. sorry that's an understatement I want it out of my life...!

    so the issue at hand is a login script that I've created which works on every browse that I've tested except safari. whenever the person logs in it returns a message of either true or the error. but since it can't determine that true is outputted by my action link it returns null in an alert box.

    Code:
      // A function to create the request object
      function createRequestObject() {
    	var ro;
    	var browser = navigator.appName;
    	if (browser == "Microsoft Internet Explorer") {
    	  ro = new ActiveXObject("Microsoft.XMLHTTP");
    	} else {
    	  ro = new XMLHttpRequest();
    	}
    	return ro;
      }
    
      // A function that sends a request
      function sendRequest(action) {
    	http = createRequestObject();
    	http.open('GET', action);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
      }
    
      // A function to catch and handle the data processed
      function handleResponse() {
    	if (http.readyState == 4) {
    	  var response = http.responseText;
    	  if (response == "true") {
    		window.location = "/index.php";
    	  } else {
    		alert(response);
    	  }
    	}
      }
    I've tried using other scripts with the same function but nothing has been useable. help is most appreciated from someone who actually knows what they are doing.

    cheers,
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  2. #2
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what version of Safari are you testing on? If I take your code and just add in handleResponse('http://www.google.com'); at the end, I get alerted the HTML source code of Google, so it is sending and receiving just fine on Safari 2.

  3. #3
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I do believe it's Safari 2. The user that's having the issue just got a new Macbook Pro...so it should be the newest version of Safari.

    You mean sendAction("http://www.google.com"); well...not sure it can't be something with my script it works on every other browser. Try creating a PHP script with just true in it. That's all my script does verifies user login info then returns either true or the error message no header, body tags etc.
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  4. #4
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well we're both wrong, I mean sendRequest

    I created a test page on localhost and it works fine too.

    Here is my test.html:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    	<title>Test</title>
    	<script type="text/javascript" charset="utf-8">
    		// A function to create the request object
    		function createRequestObject() {
    			var ro;
    			var browser = navigator.appName;
    			if (browser == "Microsoft Internet Explorer") {
    			  ro = new ActiveXObject("Microsoft.XMLHTTP");
    			} else {
    			  ro = new XMLHttpRequest();
    			}
    			return ro;
    		}
    
    		// A function that sends a request
    		function sendRequest(action) {
    			http = createRequestObject();
    			http.open('GET', action);
    			http.onreadystatechange = handleResponse;
    			http.send(null);
    		}
    
    		// A function to catch and handle the data processed
    		function handleResponse() {
    			if (http.readyState == 4) {
    			  var response = http.responseText;
    			  if (response == "true") {
    				window.location = "/index.php";
    			  } else {
    				alert(response);
    			  }
    			}
    		}
    
    		sendRequest('test_request.php');
    	//]]>
    	</script>
    </head>
    
    <body>
    	<p>Test in progress...</p>
    </body>
    </html>
    And my test_request.php:
    PHP Code:
    <?php

    echo "true";
    I haven't modified anything in your javascript, and it works just fine in Safari 2.0.4.

    It has to something else in another part of your javascript causing the problem, because what you have posted is fine.

  5. #5
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arg. Maybe I'm setting the wrong header information? I've posted it here for you to see:

    Code:
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html>
     <head>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <title>Manager Login</title>
       <script src="/js/validateforms.js" type="text/javascript"></script>
       <script src="/login/js/index.js" type="text/javascript"></script>
       <link rel="Shortcut Icon" type="image/ico" href="/images/favicon.ico" />
       <link rel="stylesheet" href="/css/main.css" type="text/css" />
     
     </head>
     <body class="t_bodymini" onLoad="document.forms.login.username.focus()">
     	  <!-- End header template !-->
     		  
     	<SCRIPT TYPE="text/javascript">
     	function validateOnSubmit() {
     	  var elem;
     	  var errs = 0;
     	  if (! validatePresent(document.forms.login.password, 'req_password', true)) { errs += 1; }
     	  if (! validatePresent(document.forms.login.username, 'req_username', true)) { errs += 1; }
     	  if (errs >= 1)  {
     		alert('There is an empty field in your form.');
     		return 0;
     	  }	
     	  sendRequest("/login/ajax_index.php?username=" + document.forms.login.username.value + "&password=" + document.forms.login.password.value);
     	}
     	function checkEnter(e){ //e is event object passed from function invocation
     	  var characterCode
     	  if (e && e.which){ //if which property of event object is supported (NN4)
     		e = e
     		characterCode = e.which //character code is contained in NN4's which property
     	  } else {
     		e = event
     		characterCode = e.keyCode //character code is contained in IE's keyCode property
     	  }
     	  if (characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
     		validateOnSubmit()
     	  }
     	}
       </SCRIPT>
       <br /><br /><br /><br /><br /><br /><br />
       <form name="login">
     	<table width="334" align="center" bgcolor="#535D5F">
     	  <tr>
     		<td height="86"><div align="center"><span style="width: 50;"><img src="/images/logo.gif" alt="Main Logo" /></span></div></td>
     
     		<td height="86" colspan="2"><div align="left"><strong>Management Software</strong><br />Version Dev-1.0</div>	  </td>
     	  </tr>
     	  <tr>
     		<td width="105" align="right">Username:</td>
     		<td width="150">&nbsp;<input onChange="validatePresent(this, 'req_username', true);" name="username" id="username" type="text"></td>
     		<td id="req_username" width="63">&nbsp;</td>
     	  </tr>
     
     	 <tr>
     		<td align="right">Password:</td>
     		<td>&nbsp;<input onKeyDown="checkEnter(event);" onChange="validatePresent(this, 'req_password', true);" name="password" id="password" type="password"></td>
     		<td id="req_password">&nbsp;</td>
     	  </tr>
     	  <tr>
     		<td height="36">&nbsp;</td>
     		<td colspan="2">&nbsp;<input onClick="return validateOnSubmit()" type="button" style="height: 30px;" name="login" value="Login Now" /></td>
     
     	  </tr>
     	</table>
     	<br />
     	<table width="334" align="center" cellpadding="5" bgcolor="#535D5F">
     	  <tr>
     		<td><div align="center">System services are running normally. </div></td>
     	  </tr>
     	</table>
     
     	<p>&nbsp;</p>
       </form>
     		  
     	  <!-- Begin footer template !-->
     </body>
     </html>
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,861
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    It would be the headers in the file being retrieved not the headers in the calling page that would be the problem.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, we just realized something important.

    If you click the submit button in the example I provided it seems to work fine. But when you press enter on the password field, which calls checkEnter(), it gives a null value.

    I don't see why there would be a difference in calling validateOnSubmit() from within checkEnter or directly in the onClick.
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  8. #8
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why wouldn't you just put the form on submit function in the form element's onsubmit handler? That way it gets called no matter how the user submits the form, and you don't have to check the other form elements for if a user presses enter since forms support being submitted that way.

    HTML Code:
    <form name="login" onsubmit="return validateOnSubmit();">

  9. #9
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    erm...*smiles* that's a really good point actually. Shoot I forgot you could use onSubmit. -_- Ok I'll switch it today but still...it's strange that it wouldn't work on JUST Safari yet work everywhere else. Ack.
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •