3

I have an external URL that gets parameters and prints a result like this: {"result": "not_avail"}

I'm trying to use jQuery to get the result like this:

$.get("http://www.thepage.html?id=2&name=david", function(data){
    alert("Data Loaded: " + data);
});

But nothing happens, I'm not getting an alert and not getting any errors in firebug. How can I solve this?

2
  • 1
    Due to same domain policy you wont get a result, try looking into jsonp Commented Nov 22, 2011 at 8:51
  • 1
    If the return is JSON, please use $.getJSON Commented Nov 22, 2011 at 9:00

3 Answers 3

3

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

from official documentation

Try to use relative path tou your script (on same domain)

Sign up to request clarification or add additional context in comments.

4 Comments

so there is no way i can get this data ?
is there any other way to do so ?
I agree with @arthur :-), if you really need this then make a php proxy script on your domain.
thanks i used this code and it is working :-) $jsonurl = "mysite.com?id=1"; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json);
0

Arthur is correct, if you are running PHP you can try something like this also for corssdomain ajax

http://phpfour.com/blog/2008/03/cross-domain-ajax-using-php/

Comments

0

Try getJSON

$.getJSON("http://yoururl",function(data){
    $("#selector").data("JSONP",data);
});

To return data in JSON format you can use json_encode() in PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.