laravel SyntaxError: Unexpected token / ... Blueimp jQuery 文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15734235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SyntaxError: Unexpected token / ... Blueimp jQuery File Upload
提问by coryj
I set up this multiple file upload plugin (https://github.com/blueimp/jQuery-File-Upload) on my local machine (mac osx default server). Everything is working perfectly, when I upload an image I get back this response
我在本地机器(mac osx 默认服务器)上设置了这个多文件上传插件(https://github.com/blueimp/jQuery-File-Upload)。一切正常,当我上传图片时,我会收到此回复
[{
"name":"subaru-wrx-poster-i3(1).jpg",
"size":142583,"type":"image\/jpeg",
"url":"http:\/\/shipwatchpointe.dev\/bundles\/jupload\/uploads\/files\/52\/subaru-wrx-poster-i3%20%281%29.jpg",
"thumbnail_url":"http:\/\/shipwatchpointe.dev\/bundles\/jupload\/uploads\/thumbnails\/52\/subaru-wrx-poster-i3%20%281%29.jpg",
"delete_url":"http:\/\/shipwatchpointe.dev\/upload\/upload\/?file=subaru-wrx-poster-i3%20%281%29.jpg&_method=DELETE",
"delete_type":"POST"
}]
However, I just pushed to a staging area on an EC2 instance and now I'm getting this response
但是,我只是推送到 EC2 实例上的暂存区,现在我收到了此响应
//
With an error on the frontend that says...
前端有一个错误说......
SyntaxError: Unexpected token /
I threw a bunch of dies everywhere I could think of but I'm not reaching them and still getting the same response. The EC2 instance is running Ubuntu 12.10 and I ensured that in /etc/mime.types that application/json json is there, but for some reason it looks like it is still trying to render it as html and throwing me that error. What could be the issue here on my staging server that's not present on my local server? I can paste my code, but there are a lot of snippets that I suspect may be causing the issue.
我在我能想到的任何地方扔了一堆骰子,但我没有接触到它们并且仍然得到相同的响应。EC2 实例正在运行 Ubuntu 12.10,我确保在 /etc/mime.types 中存在 application/json json,但出于某种原因,它似乎仍在尝试将其呈现为 html 并抛出该错误。我的本地服务器上不存在的临时服务器上可能存在什么问题?我可以粘贴我的代码,但我怀疑有很多片段可能会导致问题。
EditHere are the response headers on my local server (works fine)
编辑这是我本地服务器上的响应标头(工作正常)
Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:1532
Content-Type:image/png
Date:Wed, 03 Apr 2013 18:13:47 GMT
ETag:"30d598-5fc-4d978d09b8a80"
Keep-Alive:timeout=5, max=100
Last-Modified:Wed, 03 Apr 2013 18:13:46 GMT
Server:Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch mod_ssl/2.2.22
OpenSSL/0.9.8r
Here are the response headers on my staging server (not working)
这是我的登台服务器上的响应标头(不工作)
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:23
Content-Type:text/html
Date:Wed, 03 Apr 2013 18:07:24 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.22 (Ubuntu)
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.10-1ubuntu3.6
采纳答案by Mike Rockétt
There may be an issue with reading files here. Check/Grep your staging server for any source files that have the double slash //
in weird places (say the beginning of a PHP file).
此处读取文件可能存在问题。检查/Grep 临时服务器是否有任何//
在奇怪位置(例如 PHP 文件的开头)带有双斜杠的源文件。
It may be running into that file, erroneously printing those slashes, and ending output.
它可能会运行到该文件中,错误地打印这些斜杠并结束输出。
If this is the case, the BlueImp code is more than likely not being seen by the server, hence all those plain and simple output headers that have absolutely nothing to do with the upload.
如果是这种情况,BlueImp 代码很可能不会被服务器看到,因此所有那些与上传完全无关的简单明了的输出标头。
回答by Drew Khoury
https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
Using jQuery File Upload (UI version) on PHP websites The provided example implementation works out of the box and only needs one step for you to add it to your PHP based website:
Download the plugin archive, extract it and upload the extracted folder (you may rename it) to your server. Visit the uploaded directory - you should see the same file upload interface as the demo, allowing you to upload files to your website.
If uploading files doesn't work, make sure that the php/files and php/thumbnails directories permissions allow your server write access.
在 PHP 网站上使用 jQuery 文件上传(UI 版本) 提供的示例实现开箱即用,您只需一步即可将其添加到基于 PHP 的网站:
下载插件存档,解压缩并将解压缩的文件夹(您可以重命名)上传到您的服务器。访问上传目录 - 您应该看到与演示相同的文件上传界面,允许您将文件上传到您的网站。
如果上传文件不起作用,请确保 php/files 和 php/thumbnails 目录权限允许您的服务器写入访问。
Are you sure you have the correct permissions for "php/files" and "php/thumbnails" ?
您确定您对“php/files”和“php/thumbnails”拥有正确的权限吗?
Those are really the only installation instructions I could find. Did you simply just copy the files to your server or are you using your own implementation? Sometimes it helps to start with the simplest example, then add your stuff afterwards to rule out some of the more obvious problems.
这些确实是我能找到的唯一安装说明。您是简单地将文件复制到您的服务器还是使用您自己的实现?有时从最简单的例子开始,然后添加你的东西以排除一些更明显的问题是有帮助的。
If you have changed the code, it will help to have a look at your changes, there might be something there that is causing the issue.
如果您更改了代码,那么查看您的更改会有所帮助,那里可能存在导致问题的原因。
回答by Drew Khoury
Your content type looks different on local vs webserver. Looks like it may be an improperly configured web server.
您的内容类型在本地和网络服务器上看起来不同。看起来它可能是配置不当的 Web 服务器。
回答by Shamoon
Does your upload folder have write permission?
你的上传文件夹有写权限吗?