Javascript: Three.js JSON error on remote server, but not on local

血红的双手。 提交于 2019-12-13 03:44:45

问题


I'm writing a Three.js application. In part of it, I load a blender model exported as a JSON file using the Blender->JSON exporter for Three.js. I have WAMPServer 2.2 configured on my local computer (Windows 7) that I use to test my website before I FTP it to the remote server to show off to friends and such.

Loading this JSON file works fine on the local test server, but when I upload it to the server, I get the following error in Firebug, Firefox 16.0.2:

SyntaxError: JSON.parse: unexpected character
  var json = JSON.parse( xhr.responseText );
  three.js (line 7810)

It's finding the JSON file fine - the GET shows up in Firebug. The loading of the model is, as far as I can tell, the only loading of JSON I have in the entire script; the model also doesn't show up remotely, where it does locally. Here's the function with the load in it:

//Adds a unit to the scene. Assumes Init() hasn't been called on the unit yet.
function pubAddUnit(unit, coord, modelSrc)
{
    //Do whatever initialization the unit has to do
    unit.Init();

    //Store the unit in its position on the grid
    units[coord.y][coord.x] = unit;

    //Load the unit model
    var loader = new THREE.JSONLoader();
    loader.load(modelSrc,
            //Function called once the unit model is loaded
            function(geometry) {
                //Create a new material for the unit
                var material = new THREE.MeshFaceMaterial();
                var mesh = new THREE.Mesh(geometry, material);
                //Store the unit geometry and mesh into their respective grids
                unit.SetGeo(geometry);
                unit.SetMesh(mesh);

                //Move the mesh to the correct spot
                mesh.position = TransCoord2(coord);
                mesh.scale.set(40, 40, 40);

                //Add the mesh to the scene
                scene.add(mesh);

                //Update the scene, now with the mesh in
                update();
            });
}

And here's the javascript file, as showing on the remote server. Any ideas on why this is happening is appreciated.


EDIT: I'm using FileZilla to FTP. I did suddenly notice that the filesize of the JSON file on the server differs from that of the local, but I'm not sure if that's something I need to worry about or not - perhaps it's line endings or something?


Also, here is the JSON file.


回答1:


Ok, so I figured out the "problem"... Turns out the file isn't getting the JSON file at all, but simply a response that says "hacked by hacker" - I just didn't look at the GET response closely enough. I think all GETs from the site are being redirected to this file, "hacked by hacker." Obviously, this is outside of the scope of this question, but if anyone has any info that could help, please let me know.



来源:https://stackoverflow.com/questions/13447334/javascript-three-js-json-error-on-remote-server-but-not-on-local

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!