0

I just can't get the results from jquery.get() function and can't figure out why.

Here's the code:

$('#some_button').live('click', function (e){
  var nr="some_number";
  var id="some_id";
  $.get('http://www.somelink.com',{PAGE_ID: id, nr: nr}, function(data) {
    alert(data);
  });
});

So, when I click the button, HTTP request is sent and after 10 seconds I get the reply and the result that I need with HTTP 200 OK (I used wireshark), but the data is not alerted back to the browser.

Any ideas why?

BR, Newman

ZeZe
  • 3
  • 1

2 Answers2

3

You appear to be using $.get to obtain information from a different domain, which is prohibited by all respectable browsers. You can only use $.get on same-domain requests.

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
  • Oh, I totally forgot about this! Or should I say, I thought that this works with jquery get() :) So any idea how to bypass this? – ZeZe Oct 24 '11 at 14:54
  • The only way to get data cross-domain is with JSONP -- http://api.jquery.com/jQuery.getJSON/#jsonp -- and this uses a very specialized format. – Blazemonger Oct 24 '11 at 14:56
  • You can also use a server-side script to scrape the other domain and serve that up with `$.get` instead: http://phpfour.com/blog/2008/03/cross-domain-ajax-using-php/ – Blazemonger Oct 24 '11 at 14:58
  • I think I'll use the server side script..THank you for help! – ZeZe Oct 24 '11 at 15:01
0

The reason could quite not what your expecting, Assuming your trying to request something from a different domain then where the script is running. Your browser will be causing a Cross Domain error.

You could use jsonp or interperatate the request on your own server.

This (Cross Domain AJAX Querying with jQuery) May help

kylewelsby
  • 4,031
  • 2
  • 29
  • 35