Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts

    No Idea Where to Begin With AJAX

    I've been doing some Googling, but I haven't managed to find a very simple and easy-to-understand introduction to AJAX.

    I know a decent amount of PHP and a bit of JavaScript, and certainly know my HTML and CSS: so I'm pretty confident I can handle jumping into some AJAX as long as I know how exactly it works.

    Does anybody know of any great resources for the absolute beginner? Or perhaps a bare-bones page that uses AJAX for something very simple?

    Any help is appreciated.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dean440 View Post
    I've been doing some Googling, but I haven't managed to find a very simple and easy-to-understand introduction to AJAX.

    I know a decent amount of PHP and a bit of JavaScript, and certainly know my HTML and CSS: so I'm pretty confident I can handle jumping into some AJAX as long as I know how exactly it works.

    Does anybody know of any great resources for the absolute beginner? Or perhaps a bare-bones page that uses AJAX for something very simple?

    Any help is appreciated.
    try this:

    http://www.xul.fr/en-xml-ajax.html

    best regards

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here's another site that guided me through three AJAX pages and has helped me ALMOST get one of my own completed - http://www.w3schools.com/php/php_ajax_intro.asp

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Thanks, both of you. I'm starting to get the hang of it a bit.

    I can see this would be very powerful to use with PHP, so the most important thing to know is how to send PHP back to the JavaScript.

    Apparently, the open() method for an XMLHttpRequest object is how you open a connection with another file.. something like this, right?
    Code:
    XHR.open("GET","myPage.php?name="+name,true);
    So where does that take me on myPage.php, and how do I return a response? I'm guessing it's just a simple return, but I've having tons of problems. Once in a blue moon I got my return values to come up...but not as expected. It ended up that the PHP code "leaked through" in the return values, much like a switch statement would. And instead of returning formatted HTML like I wanted it to, it returned plain-text PHP code. Probably has something to do with me using the responeText attribute, I guess?

    And must AJAX work be hosted on a server somewhere, or can it be tested on a local machine? I know HTTP Requests to a server are involved, so I don't know if just having xAMPP with Apache and all that will cut it.

    Lastly, I read somewhere that coding AJAX "CAN be done by hand, but it's usually easier to use tools to help you."

    Is it really THAT much of a pain? It seems no harder than coding some PHP and Javascript.
    Last edited by Dean440; 12-17-2009 at 07:42 AM.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dean440 View Post
    Thanks, both of you. I'm starting to get the hang of it a bit.

    I can see this would be very powerful to use with PHP, so the most important thing to know is how to send PHP back to the JavaScript.

    Apparently, the open() method for an XMLHttpRequest object is how you open a connection with another file.. something like this, right?
    Code:
    XHR.open("GET","myPage.php?name="+name,true);
    So where does that take me on myPage.php, and how do I return a response? I'm guessing it's just a simple return, but I've having tons of problems. Once in a blue moon I got my return values to come up...but not as expected. It ended up that the PHP code "leaked through" in the return values, much like a switch statement would. And instead of returning formatted HTML like I wanted it to, it returned plain-text PHP code. Probably has something to do with me using the responeText attribute, I guess?
    two things here:
    - what you print, echo, your output, in the php script will be send back to javascript as responseText or responseXML, depend of how you want to do
    - you can send from php a response in html/xml format and insert somewhere in the page but usualy is better to send only data and format the page using javascript. For example you can use json_encode in php to transform a array in a javascript oblect, send to javascript and there you can make a list, a table or something else.

    And must AJAX work be hosted on a server somewhere, or can it be tested on a local machine? I know HTTP Requests to a server are involved, so I don't know if just having xAMPP with Apache and all that will cut it.
    firefox and firebug extension for ffox can help a lot with ajax.

    Lastly, I read somewhere that coding AJAX "CAN be done by hand, but it's usually easier to use tools to help you."

    Is it really THAT much of a pain? It seems no harder than coding some PHP and Javascript.
    Any answer to this is a personal opinion, I don't think is a pain, it's very easy in fact if you understand basic things. Ajax is just a server side language, php in this case and javascript. What is different is that you use a new javascript object XMLHTTPRequest to make connection between php and javascript.

    best regards

  • #7
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basic theory is very important .
    suggest you read the prototype.js


    ---------------------------------------------------------
    http://www.buceshi.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •