tags:

views:

46

answers:

3

hello.. i tried these two codes but it is not functioning.. i only want to ask for the data output from another domain from http://vrynxzent.info/hello.php

first code

$.post("http://vrynxzent.info/hello.php",function(e){
    alert(e);
});

second code

alert(askData());
function askData()
{
 var strUrlList = "http://vrynxzent.info/hello.php";
 var strReply = "";

 jQuery.ajax({
  url:strUrlList, success:function(html){strReply = html;}, async:false
 });
 return strReply;
}

is there another way for this? or is it posible to do this? i want the "Hello World!" output to store in a variable in javascript..

+3  A: 

Same old same origin policy.

The most common way to solve this is to do query in back-end (php in your case). I.e., browser sends ajax request to your host, which sends requests to other domain, receives response and sends it back to browser.

There're also some options if you own that other domain. JSONP, for example.

edit
Forgot to tell, this jquery plugin allows cross-domain requests through YQL. Tried myself.
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
It doesn't work in all cases (in particular, if webmaster has banned robots from his site), but it's still fairly simple and usable.

Nikita Rybak
still its not working.. but thank you for the reply sir.. :)
vrynxzent
+1  A: 

By default this does not work because of the "Same Origin Policy."

There are workarounds... see: http://www.ajax-cross-domain.com/

Fosco
+1  A: 

Because of same origin policy you cannot make ajax requests like this to some other domain,.

i would suggest using a proxy in between,.

for that what you have to do is have a script proxy.php on your own domain and then your ajax request will be

$.post( 'proxy.php' )

then proxy.php would send a request to http://vrynxzent.info/hello.php using curl and send you back the response

ovais.tariq
im not familiar with proxy.. :) so where can i learn those things?
vrynxzent
i got it sir.. :) thank you so much for the hint.. ;)
vrynxzent
np, you dont need to learn anything about proxy, the proxy script would only be making requests to another domain using curl.,
ovais.tariq