-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
68 lines (51 loc) · 1.91 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>jQuery Ajax Proxy</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h1>jQuery Ajax Proxy Sandbox</h1>
<form id="example_form">
<label>Custom Field 1</label>
<input type="text" value="" name="custom1" />
<label>Custom Field 2</label>
<input type="text" value="" name="custom2" />
<select name="method">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="PUT">PUT</option>
<option value="DELETE">DELETE</option>
</select>
<button type="submit" value="Submit">Submit</button>
<h2>To see what is going on, look at the requests that are made in your console</h2>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://sandbox1.tysonlloydcadenhead.com/ajaxproxy/jquery-ajaxproxy.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#example_form').submit(function () {
$.ajax({
url: 'http://sandbox2.tysonlloydcadenhead.com/ajaxproxy/example.json',
requestProxy: 'http://sandbox2.tysonlloydcadenhead.com/ajaxproxy/exampleRequestProxy.html',
responseProxy: 'http://sandbox1.tysonlloydcadenhead.com/ajaxproxy/exampleResponseProxy.html',
data: {
custom1: $('input[name=custom1]').val(),
custom2: $('input[name=custom2]').val()
},
type: $('select[name=method]').val(),
success: function (data) {
console.log('Success', data);
$('body').append('<strong>Response:</strong> ' + data.message + '<br />');
},
error: function (data) {
console.log('Error', data);
$('body').append('There was an error because PUT and DELETE request are not supported by my static JSON file.<br />');
}
});
return false;
});
});
</script>
</body>
</html>