Jump to content

Fill in SSN - 'entry not found' - msg


leso9903

Recommended Posts

Hello

I'm suppose to create a registration form that searches through a php-file and comments "entry not found" when the wrong social security is typed. I've no clue what I'm doing but atleast I got a apache server started...

What should I type in my jscript file? The php-script that I'm suppose to use don't contain any data, I'm confused..

 

HTML

<html>	  <head><script type="text/javascript" src="scripts.js"></script>  </head>  <body>      <?php	 echo date('c');	 ?>    </p>        <form name="form" action="" method="post">      <fieldset>  	<legend>Name and address</legend>	<div id="myDiv"></div>  	SSN: <input type="text" id="SSN" onkeyup="lookUp()"/><br>	<div id="underInput" /><br>  	Full name: <input onkeyup="showHint2(this.value)" type="text" id="fullname" name="full"><br>	<div id="txtHint2"></div> 	Street and number: <input type="text"><br>	Postal code: <input type="text"><br>	City: <input type="text">      </fieldset>            <fieldset>	<legend>Username and password</legend>  	Username: <input type="text"><br>  	Password: <input type="text"><br>	<input type="checkbox" name="show" value="X">Show password<br> 		      </fieldset>    </form><h3>Start typing a name in the input field below:</h3><form action=""> First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" /></form><p>Suggestions: <span id="txtHint"></span></p>     </body></html>

JSCRIPT

function lookUp(){    $.getJSON( "ssn_lookup.php" ,      //The URL to perform the lookup 	       {ssn: "121212121212" }, //The data you send 	       function (result){     //The function to fire upon return 		   if (!result){       //result is JSON formatted 	               (Execute if SSN does not exist) 	           } 	           else {	               (Execute if SSN exists) 	           }	       });}

Server PHP file

<?php//          FILE: ssn_lookup.php//// LAST MODIFIED: 2006-03-23////        AUTHOR: Troy Wolf <troy@troywolf.com>////   DESCRIPTION: Allow scripts to request content they otherwise may not be//                able to. For example, AJAX (XmlHttpRequest) requests from a//                client script are only allowed to make requests to the same//                host that the script is served from. This is to prevent//                "cross-domain" scripting. With proxy.php, the javascript//                client can pass the requested URL in and get back the//                response from the external server.////         USAGE: "proxy_url" required parameter. For example://                http://www.mydomain.com/proxy.php?proxy_url=http://www.yahoo.com//// proxy.php requires Troy's class_http. http://www.troywolf.com/articles// Alter the path according to your environment.require_once("class_http.php");/*  $proxy_url = isset($_GET['proxy_url'])?$_GET['proxy_url']:false;  if (!$proxy_url) {  header("HTTP/1.0 400 Bad Request");  echo "proxy.php failed because proxy_url parameter is missing";  exit();  } */$proxy_url = "http://www.it.uu.se/edu/course/homepage/websiteconst/st13/assignments/4/scripts/ssn_lookup";// Instantiate the http object used to make the web requests.// More info about this object at www.troywolf.com/articlesif (!$h = new http()) {    header("HTTP/1.0 501 Script Error");    echo "proxy.php failed trying to initialize the http object";    exit();}$h->url = $proxy_url;$h->postvars = $_REQUEST; //$_POSTif (!$h->fetch($h->url)) {    header("HTTP/1.0 501 Script Error");    echo "proxy.php had an error attempting to query the url";    exit();}// Forward the headers to the client.$ary_headers = explode("n", $h->header);foreach ($ary_headers as $hdr) {    header($hdr);}// Send the response body to the client.echo $h->body;?>
Link to comment
Share on other sites

The Javascript code needs to get the current value of the SSN field and send that to the server. You're not using the result variable in the ajax callback correctly though, the result variable will be true if the request succeeded, or false if the request did not succeed (e.g., there was a 404 error, 501, error, etc). The request will succeed whether or not the SSN was found, I assume. I don't know what the script at the proxy URL will return so I don't know what you should check for in the ajax callback. You'll need to figure out what the script returns if the SSN does or does not exist and check for that in the Javascript.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...