views:

37

answers:

2

Hi, I'm trying to POST to an external website, and display the results in a JQuery UI Dialog on my site. Is that possible? I've tried a bunch of permutations, for example (with GET):

$("#view").click(function() {
var url = this.href;
var dialog_pop = $('<div></div>');
dialog_pop.load(url).dialog();
return false; });

This seems to work if the target url is within my domain, but doesn't work if it's an external site. Also, I haven't gotten POST to work yet either.

Any ideas?

Cheers, Dean

+2  A: 

You can't do this with a normal XmlHttpRequest, which jQuery AJAX uses. This restriction is part of the same-origin policy that browsers enforce or security reasons.

What you can do is use JSONP if the other domain supports transferring data in that fashion. It's basically a specialized way of passing JSON and calling a function that exists on your side.

Nick Craver
A: 

You can send a POST to your domain like this:

$.post(url, data, function(result) {
    $('<div>' + data + '</div>').dialog();
});

However, as has already been mentioned, you cannot send a normal AJAX request to a different domain.

SLaks