简体   繁体   中英

“JQ is not defined” even though jquery is included

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

Try this: Have upload.cgi only return the javascript code you want to run

eg

redirectAfterUpload('http://upload.foobar.com/finished.php&upload=a53d7d18d879b432a2', 1);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM