0

You know the standard JavaScript include in HTML?

<script src="http://example.com/script.js"></script>

How can I post data to that src? Using AJAX or jQuery is probably not an option, unless you can get it to work cross-domain.

Gus
  • 1,905
  • 6
  • 23
  • 37
  • 1
    Why would you want to do that? Is script.js not a static file? – Brad Jul 06 '11 at 16:29
  • Don't think you can POST stuff to it easily, but you can send GET parameters to it in a simple way. Why do you need POST? – Qtax Jul 06 '11 at 16:36

1 Answers1

1

You can't post data and retrieve the content cross domain. It's a security issue.

You probably already realize this, but you can do GET requests by appending it to the url:

<script src="http://example.com/script.js?key=value&key2=value"></script>

You could also use a proxy to retrieve cross domain requests from a site. This project looks promising: https://github.com/jamespadolsey/jQuery-Plugins/tree/master/cross-domain-ajax/

But it appears to also only support GET requests through yahoo's server.

The only viable option is create a php(other other sever languages) proxy that you could filter through. It wouldn't be to difficult using php's curl API. There are equivalents in other server scripting languages.

Lime
  • 13,400
  • 11
  • 56
  • 88
  • Just curious, why does retrieving the contents of a POST request pose more of a security issue than retrieving the contents of a GET request? – Gus Jul 07 '11 at 00:26
  • In reality they are both security threats, and you actually can't retrieve the contents of a GET request either. You can only invoke remote scripts through script tags. The github project I linked to has the ability/limitation of retrieving only GET requests because that is the limitations yahoo imposed on the api. The github project is in fact a proxy through yahoos servers. JSONP was created to workaround these security issues http://stackoverflow.com/questions/2067472/please-explain-jsonp using the script tag – Lime Jul 07 '11 at 00:35