Weebly Uncaught SyntaxError: Unexpected token < in JSON at position 0 - json

I am trying to implement my unity app for my Weebly site. I followed this tutorial: https://www.youtube.com/watch?v=mf-yNlMLcqA
I have these two codes:
1.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | LearningEffective</title>
<script
src="https://pamaentertainment.weebly.com/files/theme/Build/UnityLoader.js">
</script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/Learning Effective
online.json");
</script>
</head>
<body>
<div id="gameContainer" style="width: 720px; height: 1280px; margin: auto">
</div>
</body>
</html>
2.
{
"companyName": "pama",
"productName": "LearningEffective",
"dataUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.data.unityweb",
"asmCodeUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.code.unityweb",
"asmMemoryUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.memory.unityweb",
"asmFrameworkUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.framework.unityweb",
"TOTAL_MEMORY": 268435456,
"graphicsAPI": ["WebGL 2.0", "WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"backgroundUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.jpg",
"splashScreenStyle": "Dark",
"backgroundColor": "#FFFFFF"
}
When I try to load the page where Weebly's embed code is, Chrome pops up a window with this: Uncaught SyntaxError: Unexpected token < in JSON at position 0.
How can I fix this?

The URL you are using has a space. The correct URL doesn't have one.
Change this:
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/Learning Effectiveonline.json");
To this:
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.json");

You need to set up a web server.
IIS - in file web.config:
<mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
<mimeMap fileExtension=".unityweb" mimeType="application/octet-stream" />
Apache - in file .htaccess:
AddType application/octet-stream unityweb
AddType application/json json
https://forum.unity.com/threads/webgl-uncaught-syntaxerror-unexpected-token-in-json-at-position-0.466784/
https://answers.unity.com/questions/1397472/webgl-build-when-uploaded-gives-me-this-error-unca.html

Related

I would like to modify the output of Webgl Platform Building with Unity3D

Building with WebGL creates one HTML file and one Build folder.
Remove the Build/Aa.json file from here orIt should be modified to js.
Now I'm trying to put json's content in HTML but it doesn't work.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | TyphoonFloodRiskAssessment</title>
<script src="Build/UnityLoader.js"></script>
<script>
var json = {
"companyName": "aaaaa",
"productName": "aa",
"dataUrl": "aa_Build.data.unityweb",
"wasmCodeUrl": "aa_Build.wasm.code.unityweb",
"wasmFrameworkUrl": "aa_Build.wasm.framework.unityweb",
"TOTAL_MEMORY": 268435456,
"graphicsAPI": ["WebGL 2.0", "WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"splashScreenStyle": "Dark",
"backgroundColor": "#231F20"
};
var data = JSON.parse(json);
var gameInstance = UnityLoader.instantiate("gameContainer",
data
);
</script>
</head>
<body>
<div id="gameContainer" style="width: 1012px; height: 650px; margin: auto"></div>
</body>
</html>
The content of "var = json" is the content of aa.json.
How can you solve it?

Cesium Security Error when connecting to local WMS (or TMS) server

I am trying setting up a self hosted VR-TheWorld server and render using Cesium.
When connecting to the VR-TheWorld server using a WebMapServiceImageryProvider (or a TileMapServiceImageryProvider) in cesium it connectes and renders correctly.
When point it to my locally hosted version, cesium throws the error:
An error occurred while rendering. Rendering has stopped.<br />
SecurityError: SecurityError
I cannot work out what is causing this error to occur, any pointers in the right direction would be appreciated.
HTML page used to connect below.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web Viewer</title>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version (or Chrome Frame if pre-IE11). -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<script src="../Build/Cesium/Cesium.js"></script>
<style>
#import url(../Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script type="text/javascript">
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider: new Cesium.WebMapServiceImageryProvider({
url: 'http://www.vr-theworld.com/vr-theworld/tiles?',
//url: 'http://vrtw.local/tiles?',
layers: 1
}),
//imageryProvider: new Cesium.TileMapServiceImageryProvider({
//url: 'http://www.vr-theworld.com/vr-theworld/tiles1.0.0/1/',
//url: 'http://vrtw.local/tiles1.0.0/1/',
//fileExtension: 'jpeg'
//}),
baseLayerPicker: false
});
</script>
</body>
</html>
Turns out to be a CORS issue.
Once enabled on the localhost server cesium displayed the local data with no problems.

why this code is not create a file in html5

i want to create a 'abc.txt' file in the folder where the .html file exist. in html5.
i tri with this code:
<html>
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
function onInitFs(fs) {
fs.root.getFile('abc.txt', {create: true, exclusive: true}, function(fileEntry) {
}, errorHandler);
}
window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);
</script>
<input type="button" name="" id="" value="click" onclick="onInitFs(fs);"/>
</body>
</html>
But faild. Please tell me the correct method. (i tri with google chrome and letest firefox.)
From the documentation:
The LocalFileSystem interface of the File System API gives you access to a sandboxed file system.
It doesn't give you access to the main filesystem for the computer. It is a virtual one created by the browser. You can only access files in it that you put there from your own code.

Phonegap app - json + php - crossdomain not working

i have a problem with the phonegap app.
I try to connect with ajax post with simple php file which return my an array in my app.
This is simple example/tutorial from net. I try everything i read a tousends of topics, but i don't know where is problem.
My index of the phonegap app
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Minimal AppLaud App</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
function connect(e)
{
var term= {button:e};
$.ajax({
url:'http://domain.pl/replay.php',
type:'POST',
data:term,
dataType:'json',
error:function(jqXHR,text_status,strError){
alert('no connection');},
timeout:6000,
success:function(data){
$("#result").html("");
for(var i in data){
$("#result").append("<li>"+data[i]+"</li>");
}
}
});}
</script>
</head>
<body id="stage" class="theme">
<center><b>Bikes or Cars</b></center>
<center><input onclick="connect(this.value)" type="button" value="cars" /></center>
<center><input onclick="connect(this.value)" type="button" value="bikes" /></center>
<center><b>Results</b></center>
<ul id="result"></ul>
</body>
</html>
And my replay.php file
<?php
$choice =$_POST["button"];
$cars = array("Honde", "BMW" , "Ferrari");
$bikes = array("Ducaite", "Royal Enfield" , "Harley Davidson");
if($choice == "cars") print json_encode($cars);
else print json_encode($bikes);
?>
I add domain whitelist to cordova and config xml files
<access origin=".*"/>
And i don't have any ideas what is wrong.
Thanks in advance for any suggestions.
Replace
<access origin=".*"/>
with
<access origin="*"/>
Maybe it will solve a problem.

SWFObject relative path

Whatever I try I couldn't make this swf file work.
if I put all the files into my root everything works perfectly fine.
Here is my path format;
root: where my index.php located.
inside the root, I have a folder called "public".
inside "public" I have another folder called "_carousel_flash".
This is the place where my swf file is located.
I also have "js" folder located in this directory.
Here is the html code I'm using for adding the swf file.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Galleria - Inspire Creativity</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="public/_carousel_flash/js/swfobject.js"> </script>
<script type="text/javascript" src="public/_carousel_flash /js/swfaddress.uncompressed.js"></script>
</head>
<body>
<div id="contents">
</div>
<script type="text/javascript">
var so = new SWFObject("public/_carousel_flash/block_slider.swf", "movie", "100%", "100%", "8", "#ffffff");
so.addParam("quality", "high");
so.addParam("id", "movie");
so.addParam("allowFullscreen", "true");
so.write("contents");
so.addParam("salign", "t");
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Galleria - Inspire Creativity</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="public/_carousel_flash/js/swfobject.js"> </script>
<script type="text/javascript" src="public/_carousel_flash /js/swfaddress.uncompressed.js"></script>
</head>
<body>
<div id="contents">
</div>
<script type="text/javascript">
var so = new SWFObject("public/_carousel_flash/block_slider.swf", "movie", "100%", "100%", "8", "#ffffff");
so.addParam("quality", "high");
so.addParam("id", "movie");
so.addParam("allowFullscreen", "true");
so.write("contents");
so.addParam("salign", "t");
</script>
</body>
</html>
PUBLIC spell mistake
Or else i guess <script> tag is causing some issues, try embedding your swf object file
I can't be sure what's causing your error, but here are some things I notice about your code:
You're using SWFObject 1.x, which is very outdated and uses different syntax than SWFObject 2.x. Do you have the correct swfobject.js file for SWFObject 1.x? This is a fairly common issue for SWFObject users.
In SWFObject 1.x, you can't addParam after the so.write statement... it will not be reflected in your page.
so.write("contents");
so.addParam("salign", "t");
should be
so.addParam("salign", "t");
so.write("contents");
You have a typo in the URL for SWFAddress (a space just before "/js/").
If you want to be sure your SWF is located in the root, try loading it directly in the browser using the absolute URL.
Speaking of absolute URLs, it's often helpful to try them in your SWFObject code, too. Your current URL is file-relative; I suggest either using a site-relative URL ("/foldername/filename.swf") or an absolute URL ("http://yourdomain.com/foldername/filename.swf").