Hi there
Finally i guess it is an jquery mobile error.
I show you the example, i have 2 html files and 1 php file:
index.html:
<html>
<head>
<title>TEST</title>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="
http://code.jquery.com/mobile/1.0/
jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="
http://code.jquery.com/
jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="
http://code.jquery.com/
mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
<div data-role="page" id="principal">
<div data-role="header">
<h1>TEST</h1>
</div><!-- /header -->
<div data-role="content">
<ul id="listado" data-role="listview" data-
inset="true" data-filter="true">
<li><a href="estacion.html?id=1">Elemento 1</
a></li>
<li><a href="estacion.html?id=2">Elemento 2</
a></li>
</ul>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
estacion.html:
<html>
<head>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="
http://code.jquery.com/mobile/1.0/
jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="
http://code.jquery.com/
jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="
http://code.jquery.com/
mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
<div data-role="page" id="linea">
<div data-role="header">
<h1 id="cabecera">TEST</h1>
</div><!-- /header -->
<div data-role="content">
<h3>Data</h3>
<p id="datos">No data</p>
<a href="index.html" data-
role="button">Volver</a>
</div><!-- /content -->
<script>
var evento;
$('#linea').live('pagehide',function (event, ui) {
console.log("closing sse");
evento.close();
delete evento;
});
$('#linea').live('pageinit',function (event1) {
var query = $(this).data("url").split("?")[1];
var id = query.replace("id=","");
console.log ("id whith value "+id);
$('#cabecera').html("TEST - "+id);
evento = new EventSource ("ejemplo.php?
id="+id);
evento.onmessage= function (e) {
console.log (e.data);
$('#datos').html(e.data);
};
});
</script>
</div><!-- /page -->
</body>
</html>
ejemplo.php:
<?php
header ("Content-Type: text/event-stream\n\n");
echo "retry: 10000".PHP_EOL;
echo "data: Tiempo: ".time().' Id: '.$_GET['id'].PHP_EOL;
echo PHP_EOL;
flush();
?>
In the above example i guess the error appears on jquery mobile call
to pageinit. It looks like everytime i access estacion.html the
pageinit add a new function to the listener. Even if you go back (with
volver button), the function registered with pageinit (which contains
the eventSource code) it is not unregistered...
In other words...everytime i click an item in the list going to the
second page, jquery mobile execute the pageinit event registering the
function one more time.
So my conclusion is that sse is working fine.
regards.
On Mar 3, 7:56 pm, Rick Waldron <
waldron.r...@gmail.com> wrote:
> On Sat, Mar 3, 2012 at 12:42 PM, PhistucK <
phist...@gmail.com> wrote:
> > Yes, but why would a new EventSource instance fire events on a previous
> > (as well as the current) EventSource instance?
> > This is why it sounds like a bug.
>
> That would indeed sound like and be a bug, but it's not reproducible with
> the code above or in any contrived tests I've tried.
>
> Rick
>
>
>
>
>
>
>
>
>
> > ☆*PhistucK*
>
> > On Sat, Mar 3, 2012 at 19:29, Rick Waldron <
waldron.r...@gmail.com> wrote:
>
> >> Hey all - I haven't posted here before, usually just a reader...
>
> >> You can "unregister" the handler by using removeEventListener
>
> >> var source = new EventSource('stream.php'),
> >> handler = function(e) {
> >> console.log(e.data);
> >> };
>
> >> source.addEventListener('message', handler, false);
>
> >> // removal...
>
> >> source.removeEventListener('message', handler);
>
> >> Rick
>
> >> On Sat, Mar 3, 2012 at 10:42 AM, PhistucK <
phist...@gmail.com> wrote:
>
> >>> Sounds like a weird bug. In my testing, it does not happen for me with
> >>> the "error" event (I do not have a real EventSource sample at hand).
> >>> You can search
crbug.com for an existing issue and star it. If you
> >>> cannot find one, file a new issue at
new.crbug.com.
> >>> Please, do not add a "+1" or "Me too" or "Confirmed" (or similar)
> >>> comment. It just wastes the time of Chrome engineers and sends unnecessary
> >>> e-mails to all of the people who starred the issue.
>
> >>> Thank you.
>
> >>> ☆*PhistucK*
> >>>> To post to this group, send email to
chromium-ht...@chromium.org.
> >>>> To unsubscribe from this group, send email to
> >>>>
chromium-html5+unsubscr...@chromium.org.
> >>> To post to this group, send email to
chromium-ht...@chromium.org.
> >>> To unsubscribe from this group, send email to
> >>>
chromium-html5+unsubscr...@chromium.org.