• jQuery .get and .ajax functions

    From Nightfox to All on Thu Feb 3 23:54:34 2011
    Hi all -

    Does anyone have experience with jQuery? I just started using it for a web page project, and I've run into an issue with the .get and .ajax functions. I want to populate a div with the contents of a file, and I've noticed it works fine when my files are up on a server, but when viewing my page on my local computer, it doesn't work. Why might that be?

    Nightfox
  • From Trash80@VERT/THEVILLE to Nightfox on Sat Feb 5 14:03:52 2011
    Re: jQuery .get and .ajax functions
    By: Nightfox to All on Thu Feb 03 2011 23:54:34

    Hi all -

    Does anyone have experience with jQuery? I just started using it for a web page project, and I've run into an issue with the .get and .ajax functions.
    I
    want to populate a div with the contents of a file, and I've noticed it work
    s
    fine when my files are up on a server, but when viewing my page on my local computer, it doesn't work. Why might that be?

    Nightfox

    Ajax requires a web server because the page making the ajax request is doing so by http not by the client (i.e. your web browser) trying to open a file.

    You need to set yourself up with a web development environment. If you are using Linux then just install Apache. If you are using Windows go grab yourself something like WAMP (http://www.wampserver.com/en/) which makes installing and managing Apache simple.

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Nightfox to Trash80 on Sat Feb 5 11:33:02 2011
    Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Sat Feb 05 2011 14:03:52

    Ajax requires a web server because the page making the ajax request is doing by http not by the client (i.e. your web browser) trying to open a file.

    But I've been able to do ajax stuff without a web server.. A while ago, I wrote a function to return an XMLHttpRequest object (supporting several different browsers), and it works whether it's on a server or on my local machine..

    Eric
  • From Trash80@VERT/THEVILLE to Nightfox on Wed Feb 9 19:04:59 2011
    Re: jQuery .get and .ajax functions
    By: Nightfox to Trash80 on Sat Feb 05 2011 11:33:02

    Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Sat Feb 05 2011 14:03:52

    Ajax requires a web server because the page making the ajax request is do
    ing
    by http not by the client (i.e. your web browser) trying to open a file.

    But I've been able to do ajax stuff without a web server.. A while ago, I wrote a function to return an XMLHttpRequest object (supporting several different browsers), and it works whether it's on a server or on my local machine..

    Eric

    Then how you implemented wasn't actually using "ajax" (I'd have to see your code). Ajax infers an asynchronous request to a server that returns XML to the calling client. If you are doing something off your local machine without a server then there is nothing returned to the client via http. The key here is via http. Maybe what you did was open a file and get the contents. But that is not ajax.

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Nightfox to Trash80 on Wed Feb 9 16:41:58 2011
    Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Wed Feb 09 2011 19:04:59

    Then how you implemented wasn't actually using "ajax" (I'd have to see your code). Ajax infers an asynchronous request to a server that returns XML to calling client. If you are doing something off your local machine without a server then there is nothing returned to the client via http. The key here via http. Maybe what you did was open a file and get the contents. But tha is not ajax.

    I was using an XMLHTTP object to fetch the contents of another file and put its contents into a div on the page. I thought that was AJAX.

    Nightfox
  • From Corey@VERT/TSGC to Nightfox on Wed Feb 9 20:27:39 2011
    Re: jQuery .get and .ajax functions
    By: Nightfox to Trash80 on Wed Feb 09 2011 04:41 pm

    Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Wed Feb 09 2011 19:04:59

    Then how you implemented wasn't actually using "ajax" (I'd have to see yo code). Ajax infers an asynchronous request to a server that returns XML calling client. If you are doing something off your local machine withou server then there is nothing returned to the client via http. The key he via http. Maybe what you did was open a file and get the contents. But is not ajax.

    I was using an XMLHTTP object to fetch the contents of another file and put contents into a div on the page. I thought that was AJAX.

    Nightfox


    wow I always thought the ajax function was for doing dishes.

    "Practise safe Lunch, Use a Condiment"


    ---
    ■ Synchronet ■ Three Stooges Gentlemens Club - Las Vegas, Nv - tsgc.dyndns.org
  • From Nightfox to Corey on Wed Feb 9 22:31:57 2011
    Re: jQuery .get and .ajax functions
    By: Corey to Nightfox on Wed Feb 09 2011 20:27:39

    wow I always thought the ajax function was for doing dishes.

    I also like Comet.
  • From Dreamer@VERT/SETXBBS to Nightfox on Thu Feb 10 13:24:00 2011
    Re: jQuery .get and .ajax fun
    By: Nightfox to Corey on Wed Feb 09 2011 10:31 pm

    Re: jQuery .get and .ajax functions
    By: Corey to Nightfox on Wed Feb 09 2011 20:27:39

    wow I always thought the ajax function was for doing dishes.

    I also like Comet.


    Me too. Comet does a good job on my java machine.

    ---
    ■ Synchronet ■ Southeast Texas BBS -- setxbbs.synchro.net
  • From Nightfox to Dreamer on Thu Feb 10 21:04:11 2011
    Re: jQuery .get and .ajax fun
    By: Dreamer to Nightfox on Thu Feb 10 2011 13:24:00

    Me too. Comet does a good job on my java machine.

    It might also work well for cleaning Perls and Rubies..
  • From Corey@VERT/TSGC to Dreamer on Thu Feb 10 22:23:41 2011
    Re: jQuery .get and .ajax fun
    By: Dreamer to Nightfox on Thu Feb 10 2011 01:24 pm

    Re: jQuery .get and .ajax fun
    By: Nightfox to Corey on Wed Feb 09 2011 10:31 pm

    Re: jQuery .get and .ajax functions
    By: Corey to Nightfox on Wed Feb 09 2011 20:27:39

    wow I always thought the ajax function was for doing dishes.

    I also like Comet.


    Me too. Comet does a good job on my java machine.


    Comet. it makes me vomit.

    "Practise safe Lunch, Use a Condiment"


    ---
    ■ Synchronet ■ Three Stooges Gentlemens Club - Las Vegas, Nv - tsgc.dyndns.org
  • From Tracker1@VERT/TRN to Nightfox on Wed Feb 16 00:19:11 2011
    Nightfox wrote:
    Does anyone have experience with jQuery? I just started using it for a web page project, and I've run into an issue with the .get and .ajax functions. I
    want to populate a div with the contents of a file, and I've noticed it works fine when my files are up on a server, but when viewing my page on my local computer, it doesn't work. Why might that be?

    Browser limitation, see: XmlHttpRequest object.

    --
    Michael J. Ryan - http://tracker1.info/

    ... FRA #109: Dignity and an empty sack is worth the sack.

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From Tracker1@VERT/TRN to Trash80 on Wed Feb 16 00:24:52 2011
    Trash80 wrote:
    Ajax requires a web server because the page making the ajax request is doing so
    by http not by the client (i.e. your web browser) trying to open a file.

    You need to set yourself up with a web development environment. If you are using Linux then just install Apache. If you are using Windows go grab yourself something like WAMP (http://www.wampserver.com/en/) which makes installing and managing Apache simple.

    For rough dev/testing VS Express web, or MonoDevelop are decent options.

    --
    Michael J. Ryan - http://tracker1.info/

    ... Immortality consists largely of boredom.

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From Corey@VERT/TSGC to Tracker1 on Wed Feb 16 11:02:07 2011
    Re: Re: jQuery .get and .ajax functions
    By: Tracker1 to Trash80 on Wed Feb 16 2011 12:24 am

    Trash80 wrote:
    Ajax requires a web server because the page making the ajax request is doi by http not by the client (i.e. your web browser) trying to open a file.

    You need to set yourself up with a web development environment. If you ar using Linux then just install Apache. If you are using Windows go grab yourself something like WAMP (http://www.wampserver.com/en/) which makes installing and managing Apache simple.

    For rough dev/testing VS Express web, or MonoDevelop are decent options.

    --
    Michael J. Ryan - http://tracker1.info/

    ... Immortality consists largely of boredom.


    I'll take my Mac with extra pickles.

    "Practise safe Lunch, Use a Condiment"


    ---
    ■ Synchronet ■ Three Stooges Gentlemens Club - Las Vegas, Nv - tsgc.dyndns.org
  • From Tracker1@VERT/TRN to Corey on Thu Feb 17 02:09:13 2011
    Corey wrote:
    For rough dev/testing VS Express web, or MonoDevelop are decent options.

    I'll take my Mac with extra pickles.

    Monodevelop runs fine on my mac.. ;)

    --
    Michael J. Ryan - http://tracker1.info/

    ... The key to immortality is first to live a life worth remembering.

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From Nightfox to Tracker1 on Thu Feb 17 07:34:04 2011
    Re: Re: jQuery .get and .ajax functions
    By: Tracker1 to Nightfox on Wed Feb 16 2011 00:19:11

    Does anyone have experience with jQuery? I just started using it for a we page project, and I've run into an issue with the .get and .ajax functions want to populate a div with the contents of a file, and I've noticed it wo fine when my files are up on a server, but when viewing my page on my loca computer, it doesn't work. Why might that be?

    Browser limitation, see: XmlHttpRequest object.

    But a while ago, I was doing some Ajax stuff with XmlHttpRequest without jQuery, and it worked on my local drive too..

    Nightfox
  • From Trash80@VERT/THEVILLE to Nightfox on Mon Feb 21 17:47:18 2011
    Re: Re: jQuery .get and .ajax functions
    By: Nightfox to Tracker1 on Thu Feb 17 2011 07:34:04

    Browser limitation, see: XmlHttpRequest object.

    But a while ago, I was doing some Ajax stuff with XmlHttpRequest without jQuery, and it worked on my local drive too..

    Nightfox

    Post your code (the one that isn't working for you).

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Nightfox to Trash80 on Mon Feb 21 17:37:25 2011
    Re: Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Mon Feb 21 2011 17:47:18

    Post your code (the one that isn't working for you).

    Here it is:
    // Loads a page in a div.
    function loadPageInDiv(pFilename, pDivName) {
    // Load the new file in the specified div.
    $.get(pFilename, {}, function(responseText){
    $("#" + pDivName).html(responseText);
    });
    }

    Nightfox
  • From Trash80@VERT/THEVILLE to Nightfox on Thu Mar 10 17:34:52 2011
    Re: Re: jQuery .get and .ajax functions
    By: Nightfox to Trash80 on Mon Feb 21 2011 17:37:25

    Post your code (the one that isn't working for you).

    Here it is:
    // Loads a page in a div.
    function loadPageInDiv(pFilename, pDivName) {
    // Load the new file in the specified div.
    $.get(pFilename, {}, function(responseText){
    $("#" + pDivName).html(responseText);
    });
    }

    Nightfox

    Sorry for the late reply.

    $.get requires a server as it is requesting the URL via HTTP GET. Try using jQuery's load like so:

    $("#"+pDivName).load(pFilename);

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Nightfox to Trash80 on Thu Mar 10 18:23:07 2011
    Re: Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Thu Mar 10 2011 17:34:52

    $.get requires a server as it is requesting the URL via HTTP GET. Try using jQuery's load like so:

    $("#"+pDivName).load(pFilename);

    Thanks for the response. I tried using load, but it still doesn't work when I run my web app locally.

    Nightfox
  • From Trash80@VERT/THEVILLE to Nightfox on Thu Mar 17 11:52:39 2011
    Re: Re: jQuery .get and .ajax functions
    By: Nightfox to Trash80 on Thu Mar 10 2011 18:23:07

    Re: Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Thu Mar 10 2011 17:34:52

    $.get requires a server as it is requesting the URL via HTTP GET. Try us jQuery's load like so:

    $("#"+pDivName).load(pFilename);

    Thanks for the response. I tried using load, but it still doesn't work when run my web app locally.

    Nightfox

    Now that is odd. I tested the above locally on my computer and it worked. Have you tested with different web browsers?

    I still think you should set yourself up with a "proper" :) testing environment. You're using Windows if I remember correctly. Try out WAMP (Windows, Apache, PHP, MySQL). It makes running an AMP stack about as easy as it gets.

    http://www.wampserver.com/en/

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Nightfox to Trash80 on Thu Mar 17 19:24:52 2011
    Re: Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Thu Mar 17 2011 11:52:39

    Thanks for the response. I tried using load, but it still doesn't work w run my web app locally.

    Now that is odd. I tested the above locally on my computer and it worked. H you tested with different web browsers?

    I did..

    I still think you should set yourself up with a "proper" :) testing environment. You're using Windows if I remember correctly. Try out WAMP (Windows, Apache, PHP, MySQL). It makes running an AMP stack about as easy it gets.

    I do have Apache, PHP, and MySQL set up, so I'm okay with doing that.. I just wanted to be able to have it work without that kind of setup so I can throw something together quick if I want to, and also to be able to share it with other people who might not have a *AMP setup on their home computer (although, I could just set it up on a server of mine and show them). Also, I thought it was weird that I used to be able to do it, but not now..

    Nightfox
  • From Tracker1@VERT/TRN to Trash80 on Mon Mar 21 01:43:22 2011
    On 3/17/2011 4:52 AM, Trash80 wrote:
    Now that is odd. I tested the above locally on my computer and it worked. Have
    you tested with different web browsers?

    I still think you should set yourself up with a "proper" :) testing environment. You're using Windows if I remember correctly. Try out WAMP (Windows, Apache, PHP, MySQL). It makes running an AMP stack about as easy as
    it gets.

    http://www.wampserver.com/en/

    WebPI makes getting WIMP (Windows, IIS, MySQL, PHP) pretty straight forward to...
    http://www.microsoft.com/web/platform/

    It's actually pretty nice for getting up and running web dev, or software in windows.

    --
    Michael J. Ryan - http://tracker1.info/

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From Trash80@VERT/THEVILLE to Nightfox on Wed Mar 30 17:47:19 2011
    Re: Re: jQuery .get and .ajax functions
    By: Nightfox to Trash80 on Thu Mar 17 2011 19:24:52

    I could just set it up on a server of mine and show them). Also, I thought was weird that I used to be able to do it, but not now..

    Nightfox

    Those are the worst kinds of problems to solve.

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Trash80@VERT/THEVILLE to Tracker1 on Wed Mar 30 17:53:07 2011
    Re: Re: jQuery .get and .ajax functions
    By: Tracker1 to Trash80 on Mon Mar 21 2011 01:43:22

    WebPI makes getting WIMP (Windows, IIS, MySQL, PHP) pretty straight forward http://www.microsoft.com/web/platform/

    It's actually pretty nice for getting up and running web dev, or software in windows.

    --
    Michael J. Ryan - http://tracker1.info/

    I've used that before and you're right, it does make the install simple.

    Regards,
    Doug
    --
    The Ville - Where 8-bits meet 32. Internet: telnet, gopher
    FidoNet: 1:255/36 URL: theville.vintagecomputing.net

    ---
    ■ Synchronet ■ The Ville...where 8 bits meet 32.
  • From Scottie@VERT/SRN to Nightfox on Thu Dec 15 15:43:41 2011
    Re: Re: jQuery .get and .ajax functions
    By: Trash80 to Nightfox on Mon Feb 21 2011 17:47:18

    Post your code (the one that isn't working for you).

    Here it is:
    // Loads a page in a div.
    function loadPageInDiv(pFilename, pDivName) {
    // Load the new file in the specified div.
    $.get(pFilename, {}, function(responseText){
    $("#" + pDivName).html(responseText);
    });
    }

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion BBS: digdist.bbsindex.com



    /////////////////////////////////

    this is what i use for my radio station
    this code will reload a div every 10 secs.
    if you want a link click version to load content into a div let me know.

    //Create a .js file call it Ajax.js paste this code into it and save it. //Ajax.js
    function Ajax(){
    var xmlHttp;
    try{
    xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
    }
    catch (e){
    try{
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
    }
    catch (e){
    try{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e){
    alert("No AJAX!?");
    return false;
    }
    }
    }

    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){

    document.getElementById('myDiv').innerHTML=xmlHttp.responseText; //The DIV ID that will hold the content
    setTimeout('Ajax()',10000);
    }
    }
    xmlHttp.open("GET","SOMEPAGE.HTML",true); // The Page to reload. xmlHttp.send(null);
    }

    //This sets the reload timer
    window.onload=function(){
    setTimeout('Ajax()',10000); //Reloads every 10 Secs.
    }



    //Example HTML document
    <html>
    <head>
    <title> ... </title>
    </head>

    <body>
    <!-- THIS does NOT have to be in the <head> section -->
    <script language="javascript" type="text/javascript" src="path_to/ajax.js"> </script>
    <!-- the div to be used -->
    <div id="myDiv">
    ... DIV CONTENT GOES HERE ...
    </div>
    </body>
    </html>

    this is a very simple way of reloading a div using ajax.

    ---
    ■ Synchronet ■ Octane BBS