|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Handler with Pjax</title> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, shrink-to-fit=no"> |
| 7 | + <link rel="shortcut icon" href="/icons/redirect.ico"> |
| 8 | + <link rel="stylesheet" type="text/css" href="assets/pjax.css" data-pjax-resource="true"> |
| 9 | + <script src="assets/pjax.js" data-pjax-resource="true"></script> |
| 10 | + <script data-pjax-resource="true"> |
| 11 | + Pjax.start(); |
| 12 | + |
| 13 | + Pjax.on("handler", function (details, done, fail) { |
| 14 | + console.log("handler request:", details.method, details.url); |
| 15 | + console.log("handler target:", details.element); |
| 16 | + console.log("handler mode history:", details.state); // 1 == push, 2 == replace |
| 17 | + |
| 18 | + setTimeout(function () { |
| 19 | + if (details.url.indexOf("/error.html") !== -1) { |
| 20 | + fail("Custom Error"); |
| 21 | + } else { |
| 22 | + done('<div id="pjax-container">Foo: ' + new Date() + '</div>'); |
| 23 | + } |
| 24 | + }, 1000); |
| 25 | + }); |
| 26 | + </script> |
| 27 | + <style type="text/css"> |
| 28 | + #notice { |
| 29 | + background-color: #188abd; |
| 30 | + color: #fff; |
| 31 | + padding: 5px 15px; |
| 32 | + } |
| 33 | + </style> |
| 34 | +</head> |
| 35 | +<body> |
| 36 | + |
| 37 | + <script type="text/javascript"> |
| 38 | + if (!Pjax.supported) { |
| 39 | + document.write('<div id="notice">'); |
| 40 | + document.write('<p>Your browser don\'t support Pjax, using normal navigation</p>'); |
| 41 | + document.write('</div>'); |
| 42 | + } |
| 43 | + </script> |
| 44 | + |
| 45 | + <ul> |
| 46 | + <li><a href="foo.html"><strong>foo.html</strong></a></li> |
| 47 | + <li><a href="bar.html"><strong>bar.html</strong></a></li> |
| 48 | + <li><a href="baz.html"><strong>baz.html</strong></a></li> |
| 49 | + <li><a href="error.html"><strong>error.html</strong></a></li> |
| 50 | + </ul> |
| 51 | + <div id="pjax-container"> |
| 52 | + <h1>Simulate navigation</h1> |
| 53 | + </div> |
| 54 | +</body> |
| 55 | +</html> |
0 commit comments