views:

75

answers:

2

Hey all i am trying to find a way to call an external website and retreve its HTML so that i can check for something in it (wither the user entered a valid VIN # or not depending on what this website calls back)

This is the code i have:

$.ajaxSetup ({

cache: false });

$("#load_callback").click(function(){ $.ajax({ url: 'http://www.google.com', dataType: 'text', success: function(data) { alert(data); } }); });

It works but only if i have it pointed to my server (and running on my server also). Is there a way i can call an external website using jquery/ajax? I am aware of the Same origin policy but was hoping something like what i want to do did not fall into that catagory?

I cant even get an iFrames title? Really??? wow....

David

+1  A: 

You need to use jsonp: http://en.wikipedia.org/wiki/JSON#JSONP

These links should explain it:

The other option you have is to write your own server-side proxy to it, i.e. have a page/controller/handler on your server that passes your request through and returns the result. It won't be as fast as going direct, and it will increase your site's traffic, but it will get you around the security problem.

Bennor McCarthy
I cant seem to find an HTML example of a call back using JSONP?
StealthRT
you get json and convert it on the fly with js. Or you can also get a full string of html data and just insert it there.
Ionut Staicu
But the other server is not looking for a JSON call nor will it call one back?
StealthRT
A: 

Stick to simple things, if you want to load websites, be simple and go with iframe. If you want to make request use PHP or similar. For example you can use curl method to make request to another websites through PHP. Or even simpler, setup a form to request to another web server.

Starx
Tried using a iframe but it gives me permission denied when trying to get the iframes innerhtml...
StealthRT
You can't interact with iframe content if it's on different domain.
Ionut Staicu