adlnet / xAPIWrapper

Wrapper to simplify communication to an LRS
https://adlnet.gov/projects/xapi/
Apache License 2.0
219 stars 114 forks source link

send state pass array is not array form one page to another page #114

Open wzhonggo opened 5 years ago

wzhonggo commented 5 years ago

Content-Type is application/json if state value is Array. But Content-Type is application/octet-stream if you pass Array form one page to another page . The reason is use instanceof to test state value .

see javascript-when-i-pass-array-from-iframe-function-the-array-lose-his-type

Test in chrome with windows 10. t1. html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function test() {
            var arr = [];
            arr.push(1);
            var r1 = arr instanceof Array;
            console.log("is array (instanceof) " + r1.toString());
            console.log("is array (Array.isArray) " + Array.isArray(arr))
            console.log("call iframe")
            window.f1.demo(arr);
        }
    </script>
</head>
<body>
<iframe src="t2.html" name="f1"  height="600" width="100%" frameborder="0" scrolling="no" onload="test()"></iframe>
</body>
</html>

t2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        demo = function (param) {
            var r1 = param instanceof Array;
            console.log("is array (instanceof) " +  r1.toString())
            console.log("is array (Array.isArray) " +  Array.isArray(param))
        }
    </script>
</head>
<body>
</body>
</html>

The consloe result

is array (instanceof) true is array (Array.isArray) true call iframe is array (instanceof) false is array (Array.isArray) true