How do you perform a HTTP GET from a remote domain in JavaScript?
(Ajax requests only seem to work on the same domain)
(I want to pass one parameter and receive back the HTML)
When it comes to foreign domains, it (as far as I know) can't be done in JavaScript/AJaX. If it were same domain, it could work. This is better suited for a dynamic scripting language, like PHP, ASP, ColdFusion, JSP, etc.
How do they do that?
What do you think of it?
Is it something similar to the YQL module, that rnd me was mentioning?
It's worth mentioning that I have all domains under my control.
So altering the access-control http headers on the server side would not be a problem.
(I'll be using PHP on the server-side)
You could make the request from the same domain server, process the get and return it. If using PHP on the back end, use http_get and perhaps something to parse the reply.
YQL is more-or-less a poor-man's simple php proxy. it's nice because it converts things to JSON, but the impossible part that is does is move bits from a restrictred domains into a JSONp url that can be added to any page using <script src=xxx /> tags.
Much thanks for your replies. Unfortunately, I do not control the original server which is iframed on my site. I am trying to populate text inside a text input located inside the iframe. I am just beginning to study my first programming language (javascript)so I am familiar with jsonp, <script src=xxx /> and the function callback, rnd me. However, php is something I have never looked at, janusmccarthy. Am I over complicating this or am I at least pointing in the right direction? Thanks again,
Teeb
@rnd me: Do you think I could use POST similarly this way, instead of GET?
yes, even delete and put could work, but it's customizable in the Access-Control-Request-Method header. if you POST anything other than urlformdata, you need that extra header in addition to your allow-origin one...
also make sure OPTIONS requests work on your server to enable pre-flights.
Actually,
There is an Iframe (mypage1) within an Iframe (mypage2) of the origin site. I have access to the two pages with the i-frames only. I don't believe the origin site is jsonp compatible and cookies must be passed. Can headers be used on my 2 iframe pages to fill in form data with in the i-frame? What type of files need the headers in case I can get the origin site to help?
Thanks for your kind replies,
teeb
Bookmarks