“JQ未定义”即使包含 jquery
好的,http://foobar.com 上的人上传到 http://upload.foobar.com/cgi-bin/upload.cgi
upload.cgi 返回:
<script language="javascript" type="text/javascript" src="http://upload.foobar.com/jquery-1.3.2.min.js">
</script>
<script language="javascript" type="text/javascript" src="http://upload.foobar.com/uploader.js">
</script>
<script language="javascript" type="text/javascript">
UploaderRemote.redirectAfterUpload('http://foobar.com/proxyajax.php?url=http://upload.foobar.com/finished.php&upload=a53d7d18d879b432a2', 1);
</script>
正确检索了 upload.cgi 中的信息,问题是跨域限制仍然适用。
我试图复制仅限于子域的 js 函数,以便它与主域分开。
从子域导入 jquery 和 uploader.js 后,我尝试运行被限制的功能。 (我在 UploaderRemote.redirectAfterUpload 之前省略了“parent”,不确定它是否需要留在那里)。
问题是,javascript 控制台说 JQ 未在 upload.foobar.com 的 uploader.js 中定义,有没有办法显式定义它?我尝试在 uploader.js 之前包含 jquery,但没有成功。
注意: http://foobar.com 有自己的 jquery & uploader.js ,但就像我之前说过的,javascript (parent.Uploader.redirectAfterUpload) 是从 http://uploader.foobar.com/cgi-bin/upload.cgi 不允许访问 http://foobar.com
OK so person on http://foobar.com uploads to http://upload.foobar.com/cgi-bin/upload.cgi
upload.cgi returns:
<script language="javascript" type="text/javascript" src="http://upload.foobar.com/jquery-1.3.2.min.js">
</script>
<script language="javascript" type="text/javascript" src="http://upload.foobar.com/uploader.js">
</script>
<script language="javascript" type="text/javascript">
UploaderRemote.redirectAfterUpload('http://foobar.com/proxyajax.php?url=http://upload.foobar.com/finished.php&upload=a53d7d18d879b432a2', 1);
</script>
The information from upload.cgi is retrieved correctly, problem is the crossdomain restriction still applies.
Im attempting to just copy the js function that is being restricted to the subdomain so that it is separate from the main domain.
After importing jquery and uploader.js from the subdomain, I try running the function that was being restricted. (I omitted "parent." before UploaderRemote.redirectAfterUpload, not sure if it needs to stay there).
Problem is, javascript console says that JQ is not defined in uploader.js from upload.foobar.com, is there a way to explicit define it? I tried including jquery right before uploader.js, but no luck.
NOTE: http://foobar.com has its own jquery & uploader.js , but like i said before, the javascript (parent.Uploader.redirectAfterUpload) being grabbed from http://uploader.foobar.com/cgi-bin/upload.cgi isn't being allowed to access the functions of uploader.js on http://foobar.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:让 upload.cgi 仅返回您想要运行的 javascript 代码,
例如
当你检索它时,只需 eval() 它。
您没有提供任何有关如何调用 upload.cgi 或如何处理其响应的示例,因此我无法提供正确的代码。
顺便说一句,如果 upload.cgi 总是应该重定向,您可以让它只返回目标 URL。
如果您想进一步研究此问题,请查找 JSONP 回调。这几乎是相同的技术。
Try this: Have upload.cgi only return the javascript code you want to run
e.g.
When you retrieve this, just eval() it.
You haven't provided any example of how you call upload.cgi or how you handle its response so I can't give proper code.
By the way, if upload.cgi is always supposed to redirect, you could have it return just the target URL.
If you want to investigate this further look for JSONP callbacks. This is pretty much the same technique.