Difference between revisions of "PHPAJAX"

From mi-linux
Jump to navigationJump to search
(Created page with "Main Page >> Web Application Development >> Workbook >> Template Engines == jQuery == == Client-side == <pre> <html> <head> <title>Ajax example</t...")
 
Line 1: Line 1:
 
[[Main Page]] >> [[CP2228|Web Application Development]] >> [[PHP|Workbook]] >> Template Engines
 
[[Main Page]] >> [[CP2228|Web Application Development]] >> [[PHP|Workbook]] >> Template Engines
 +
 +
Let's implement this very simple Ajax example: [http://mi-linux.wlv.ac.uk/~in9352/ajax/]
  
 
== jQuery ==
 
== jQuery ==

Revision as of 13:00, 6 September 2016

Main Page >> Web Application Development >> Workbook >> Template Engines

Let's implement this very simple Ajax example: [1]

jQuery

Client-side

<html>
	<head>
		<title>Ajax example</title>
		<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
		<script>
			function DoDearch()
			{
				// This is the Ajax call to "getdata.php"
				$.ajax({
				  method: "GET",
				  url: "getdata.php",
				  data: { searchValue: $('#searchValue').val() }
				})
				
				// And this handles the response
				.done(function( response ) {
					// Write response to our "results" element
					$( "#results" ).html(response);
				});		
			}
		</script>
	</head>
	<body>
		<h1>Ajax example</h1>
		Enter value: <input type="text" id="searchValue">
		<input type="button" value="Search" onclick="DoDearch();">
		<p id="results"></p>
	</body>
</html>

Server-side

<?php
	
	// Retreive value passed from Ajax call
	$searchValue = $_GET['searchValue'];
	
	// Debug message
	echo "Performing search for ".$searchValue."...";
	
	// Connect to database
	// Build SQL statement
	// Run SQL statement
	// Loop through results and display

?>