Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Created April 13, 2014 13:27
Show Gist options
  • Select an option

  • Save ruliarmando/10584104 to your computer and use it in GitHub Desktop.

Select an option

Save ruliarmando/10584104 to your computer and use it in GitHub Desktop.
ajax frontend
<!doctype html>
<html>
<head>
<title>Ajax WebService</title>
<script src="jquery.js"></script>
</head>
<body>
<form id="calc">
<input type="text" name="operand1" />
<select name="operator">
<option value="+">+</option>
<option value="*">*</option>
<option value="-">-</option>
<option value="/">/</option>
</select>
<input type="text" name="operand2" />
<input type="submit" id="submit" value="Proccess!">
</form>
<br />
<br />
<input type="text" id="result" readonly />
<script>
$(document).ready(function(){
$('#submit').click(function(e){
e.preventDefault();
$.ajax({
url: 'main.php',
type: 'post',
dataType: 'json',
data: $('#calc').serialize(),
success: function(data){
$('#result').val(data.result);
},
cache: false
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment