1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ajax/jQuery.get Retriving Data From URL

Discussion in 'jQuery' started by papa_face, Oct 31, 2009.

  1. #1
    Hey,

    Can AJAX retrieve the output from a URL and store the output of that url in a javascript var?

    The code I have is:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script><script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script><script type="text/javascript" src="js/si.files.min.js"></script><script type="text/javascript" src="js/json2.min.js"></script><script type="text/javascript" src="js/functions.js"></script><script type="text/javascript" src="js/jquery.cookie.js"></script><script type="text/javascript" src="js/jquery.blockUI.js"></script><script type="text/javascript" src="js/jquery.tools.min.js"></script><script type="text/javascript" src="js/flowplayer-3.1.2.min.js"></script><script type="text/javascript" src="js/jquery.hoverbox.min.js"></script><script type="text/javascript" src="js/global.js"></script><script 
    <script src="/js/peel/AC_OETags.js" language="javascript"></script>    
    <script src="/js/peel/pageear.js" type="text/javascript"></script><script type="text/javascript">
    $.get("http://www.url.com/test.php", function(data){ alert(data) } );
    </script>
    </head>
    <body>
    </body>
    </html>
    
    Code (markup):
    The test.php page says "hello". But when I load my page it does not show me an alert with that.

    Any idea what I am doing wrong?
    Thanks :)
     
    papa_face, Oct 31, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    AJAX requests can get data only from the same domain where the page you call script from is located.
    Except for JSON requests.
     
    AsHinE, Nov 1, 2009 IP
  3. Pintu

    Pintu Active Member

    Messages:
    88
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    In the 1990s, most sites are based on full HTML pages, where any user action required that the page is loaded from the server (or a new page loads). This process is not effective, as evidenced by the experience of the user (the entire contents, then it disappears, etc.). Every time a page is reloaded due to a partial change, all content sent again instead of just the changed data. This may put additional pressure on the server and the excessive use of bandwidth.
     
    Pintu, Oct 13, 2010 IP