[Xerte-dev] Re: QRcode page for html5 version

Smith, John J.J.Smith at gcu.ac.uk
Thu Nov 1 15:43:29 GMT 2012


Hi Ron,

Yes that is same origin policy. The only way to get around it is to use AJAX with JSONP which exploits the open policy for <script> elements (in a similar way to how you can do <img src="any_image_url">

You are in luck though, because is.gd do also do JSON and JSONP too so if you do:

http://is.gd/create.php?format=json&callback=your_function&longurl=http://nottingham.ac.uk/xerte

I'll leave it for you to look at the delicious, rss or youtuberss models to see how to do a JSONP request which shouldn't take you long.

I have included a timer because JSONP isn't ajax to doesn't timeout and throw an error so you need to handle this yourself.

Regards,

John Smith
Learning Technologist
School of Health & Life Sciences
Glasgow Caledonian University

From: xerte-dev-bounces at lists.nottingham.ac.uk [mailto:xerte-dev-bounces at lists.nottingham.ac.uk] On Behalf Of Ron Mitchell
Sent: Thursday, November 01, 2012 3:12 PM
To: 'For Xerte technical developers'
Subject: [Xerte-dev] Re: QRcode page for html5 version

Thanks John
I should have explained - I can get it working via rss_proxy but not without
I have the following:

var pastedurl = x_currentPageXML.getAttribute("url");
var shorturl = "http://is.gd/api.php?longurl="+pastedurl;
The value of pastedurl from the xml is http://nottingham.ac.uk/xerte
If I do alert(shorturl); I get http://is.gd/api.php?longurl=http://nottingham.ac.uk/xerte
and if I visit http://is.gd/api.php?longurl=http://nottingham.ac.uk/xerte in a browser window I get http://is.gd/dS1Cst so up to that point it's all working fine

But I obviously need to read in the result of shorturl to display on the page

I've tried the following:
jQuery.get(shorturl, function(data) {
    var myvar = data;
        alert(myvar);
    });
I don't get an alert

If I do
$.ajax({
        url: 'http://localhost/test.txt',
        cache: false
    }).done(function( html ) {
                alert(html);
            });
I get the results of the text file in the alert

but if I do
$.ajax({
        url: shorturl,
        cache: false
    }).done(function( html ) {
                alert(html);
            });
I don't get an alert

If I then change shorturl to
var shorturl = "http://localhost/newxottrunktest/rss_proxy.php?rss=http://is.gd/api.php?longurl="+pastedurl;
and
$.ajax({
        url: shorturl,
        cache: false
    }).done(function( html ) {
                alert(html);
            });
It works and I get the shorturl

So I guess this is the same origin policy issue?

Any suggestions?

Cheers
Ron

From: xerte-dev-bounces at lists.nottingham.ac.uk<mailto:xerte-dev-bounces at lists.nottingham.ac.uk> [mailto:xerte-dev-bounces at lists.nottingham.ac.uk] On Behalf Of Smith, John
Sent: 01 November 2012 14:32
To: For Xerte technical developers
Subject: [Xerte-dev] Re: QRcode page for html5 version

Post some code and I'll cast an eye over it...


Regards,

John Smith
Learning Technologist
School of Health & Life Sciences
Glasgow Caledonian University

From: xerte-dev-bounces at lists.nottingham.ac.uk<mailto:xerte-dev-bounces at lists.nottingham.ac.uk> [mailto:xerte-dev-bounces at lists.nottingham.ac.uk] On Behalf Of Ron Mitchell
Sent: Thursday, November 01, 2012 2:33 PM
To: 'For Xerte technical developers'
Subject: [Xerte-dev] Re: QRcode page for html5 version

Thanks John
can't get that to work at the moment :-( will try again later.
Cheers
Ron

From: xerte-dev-bounces at lists.nottingham.ac.uk<mailto:xerte-dev-bounces at lists.nottingham.ac.uk> [mailto:xerte-dev-bounces at lists.nottingham.ac.uk] On Behalf Of Smith, John
Sent: 01 November 2012 14:00
To: For Xerte technical developers
Subject: [Xerte-dev] Re: QRcode page for html5 version

Hi Ron,

To load data into the HTML5 player you'll want to do an ajax call. In its simplest form:

$.ajax({
  url: "test.html",
  cache: false
}).done(function( html ) {
  // do something with html
});

If you try to do this cross server then you may run into the same origin policy though (http://en.wikipedia.org/wiki/Same_origin_policy)

The only way to do that is to do an ajax JSON with callback request (well tehnically its not ajax) but the page must return a valid JSON object wrapped in a function name, which may require creating a new file on a remote server...

Take a look at how the delicious, rss and youtuberss ones work, it'll be similar.

One think to think about though is that If you get it working in toolkits using proxy_rss then it won't work if exported to run in a scorm player...

Regards,

John Smith
Learning Technologist
School of Health & Life Sciences
Glasgow Caledonian University

From: xerte-dev-bounces at lists.nottingham.ac.uk<mailto:xerte-dev-bounces at lists.nottingham.ac.uk> [mailto:xerte-dev-bounces at lists.nottingham.ac.uk] On Behalf Of Ron Mitchell
Sent: Thursday, November 01, 2012 1:04 PM
To: 'For Xerte technical developers'
Subject: [Xerte-dev] QRcode page for html5 version

Hi Fay
like Jonathan I thought I'd have a go with the html5 stuff and at converting one of the pages you haven't yet converted. As the QR code page was one I put together I thought I'd have a go at that. I used your textGraphics.html page as a starting point and have this working reasonably well as far as I can tell but have attached a copy here rather than committing it for now.

The bit I haven't got working and haven't even tried yet is how to grab the short url. In the flash version I used readfile() and in the case of xot use it together with rssproxy e.g.

myurl.readFile(_level0.site_url + 'rss_proxy.php?rss=' + "http://is.gd/api.php?longurl="+pastedurl);

my question is what's the equivalent of readFile for use with the xenith code? e.g. to read and display the result of something like http://is.gd/api.php?longurl="http://nottingham.ac.uk/xerte<http://is.gd/api.php?longurl=%22http://nottingham.ac.uk/xerte>" which just displays the text on screen

Cheers
Ron


This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education's Widening Participation Initiative of the Year 2009 and Herald Society's Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education's Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education's Widening Participation Initiative of the Year 2009 and Herald Society's Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education's Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education's Widening Participation Initiative of the Year 2009 and Herald Society's Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education's Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nottingham.ac.uk/pipermail/xerte-dev/attachments/20121101/4394c2f2/attachment-0001.html>


More information about the Xerte-dev mailing list