I am trying to get Amplify.js to publish / subscribe to work with 2 files.
I can make it work when the code is one file, but not when publishing in one file, but subscription in another file.
Here is the code where the subscription and publication call is in the same file. It works.
<html>
<head>
<script type="text/javascript" src="./js/jquery-1.8.2.min.js"> </script>
<script
type="text/javascript" src="./js/amplify-1.1.2/amplify.min.js">
</script>
</head>
<body>
<H1>My amp pub/sub page</H1>
<script type="text/javascript">
alert("entering page");
amplify.subscribe("dataExample", function(param) {
alert("In the amplify.subscribe function,
param is: " + param.foo ); } );
alert("after line amplify.subscribe");
result = amplify.publish("dataExample", { foo: "bar" } );
alert ("After amplify.publish, result is " + result );
</script>
</body>
</html>
The results display warnings in the expected order, like this:
"page input"
"after amplifying the line. Subscription"
'In the amplify.subscribe function, param: bar'
'After amplify.publish the result is correct "
,
amplify.subscribe .
test, ( Firefox).
, .
( )
<html>
<head>
<script type="text/javascript" src="./js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="./js/amplify-1.1.2/amplify.min.js">
</script>
</head>
<body>
<H1>My amp sub page</H1>
<script type="text/javascript">
alert("entering page");
amplify.subscribe("dataExample", function(param) {
alert("In the amplify.subscribe function, param is: " +
param.foo ); } );
alert("after line amplify.subscribe");
</script>
</body>
</html>
( )
<html>
<head>
<script type="text/javascript" src="./js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="./js/amplify-1.1.2/amplify.min.js">
</script>
</head>
<body>
<H1>My amp pub page</H1>
<script type="text/javascript">
alert("entering page");
result = amplify.publish("dataExample", { foo: "bar" } );
alert ("After amplify.publish, result is " + result );
</script>
</body>
</html>
firefox 47.0.1
, Chrome.
- ?
- , ,
? ?
, .
?
?