There and Back Again

You got AJAX questions I got Answers

Have you wondered whats the easiest way to submit a form using AJAX, what the status of HTML_AJAX development is, or what is covered in Understanding AJAX?

Well nows your chance.

Submit your questions general AJAX questions, questions about my soon to be released book Understanding AJAX, questions on HTML_AJAX, or anything else I might know the answer of, and I’ll answer them in another post a couple days from now.

19 thoughts on “You got AJAX questions I got Answers

  1. Maarten Manders

    How can I find out whether a connection is broken? Should I just set a unique timeout per request after which an error message can be displayed? The timeout would be deactivated if the AJAX call succeeds. Is this a smart idea and does it work?

  2. wesley

    Why would you want to use HTML_AJAX when there are far better tools for the job, pure javascript solutions such as prototype or jquery? I don’t think you need something special on the serverside to return some data as a response to an AJAX call.

  3. Pingback: PHPDeveloper.org

  4. Tri Pham

    What is the best way to ‘degrade’ a website when Javascript/XMLHttpRequest support is disabled? Take f.e. yahoo.com. It’s a great website enriched with AJAX, but when JS is disabled it’s still looks the same but the rich features are not there. Would you consider CSS-style selectors as the solution? I do not want to create two different websites, one JS enabled and the other JS disabled. Thank you in advance.

    Tri Pham

  5. ben bakelaar

    When utilizing an AJAX API such as Google Maps, how do you execute embedded Javascript commands in a page generated on-the-fly? For example, you have a website which contains several ‘s, one of which is an implementation of the API (i.e. a Google map). That loads when the page loads. Now, based on user interaction (clicking on links), you pull an SQL result from a database and display 10 at a time in a separate . Each time the loads, you want to execute some commands through the AJAX API. In my understanding, JS only executes at the browser page load, but I’m sure I’ve seen sites that get around this.

  6. Rok

    I’ve been studying AJAX for a bout a month now but I have not yet grasped the tecnique to submit a form with POST method. I’ve been trying to find an article that covered that but all I could find was the ones that included somekind of already made framework.

    I want to know how to submit data to server (like form or email sending) with POST method.

    Thank you for the time and answers

  7. Femi

    to Tri Pham
    I haven’t been able to use CSS Selectors in the way that’ll make my work easier, so……

    I also faced a similar challenge, but I decided to solve it “halfway”. If XMLHttpRequest is unavailable (though this was not what I was trying to solve when I created my solution), I expect that at least javascript is enabled. If it is, then i can use the solution, if javascript support isn’t enabled…..

    Almost of my modules and pages are of this format:

    http://localhost/index.php?p=schools&a=view&id=23

    Where p=page
    and a = action
    Based on this I can simulate a call of this sort in two ways.
    First thing is I set a flag to determine if I’ll be using AJAX or not
    If I am then

    useAjax = true;

    other wise I set it to false. That way, since all my ajax requests are made to a function I created in js:
    function showInfo(page,action,id){
    if (useAjax){
    ajax callback function and everything ajax :-D
    e.g ////////////////
    var callback = {
    doPortalService: function(result) {
    HTML_AJAX_Util.setInnerHTML(‘contentarea’,result);
    }
    }
    var getData = new portal(callback);
    getData.doPortalService(page,action,id);
    ///////////////
    } else {
    classic browser reload e.g.
    location.href=”http://localhost/?p=”+page+”&a=”+action+”&id=”+id;

    }

    }
    SO this way, If I ever need to disable the use of ajax tech. on the site, all I need to do is to set the useAjax flag to false. However, this solution is wholly dependent on having javascript support enabled.

    What I believe is that majority of my users (>90%) would have js support enabled, so I’m just a tiny bit worried about the tags and click on it…

    Oh well,, Let me know how it goes….

    Femi Taiwo
    QUOTE
    # Tri Pham Says:
    August 11th, 2006 at 1:11 pm

    What is the best way to ‘degrade’ a website when Javascript/XMLHttpRequest support is disabled? Take f.e. yahoo.com. It’s a great website enriched with AJAX, but when JS is disabled it’s still looks the same but the rich features are not there. Would you consider CSS-style selectors as the solution? I do not want to create two different websites, one JS enabled and the other JS disabled. Thank you in advance.

    Tri Pham
    /QUOTE

  8. Pingback: There and Back Again » Blog Archive » AJAX Question updates

  9. Pingback: There and Back Again » Blog Archive » AJAX Answers

  10. Some guy

    Tri pham sayd JavaScript OFF, how would this code run:
    classic browser reload e.g.
    location.href=”http://localhost/?p=”+page+”&a=”+action+”&id=”+id;
    ???????
    Also what you do with back button, hash?, frame?, how?!?

  11. Femi

    [Quote]
    Tri pham sayd JavaScript OFF, how would this code run:
    classic browser reload e.g.
    location.href=”http://localhost/?p=”+page+”&a=”+action+”&id=”+id;
    ???????
    Also what you do with back button, hash?, frame?, how?!?
    [/Quote]
    TO: Tri pham & Some Guy
    Well the only other way is to have a massive amount javascript all over in the html, either using css selectors like behaviours.js OR is to do something like this
    ——
    View full article
    ——-

    And write the function showInfo() to always return false. SO if JS is disabled, the onclick event is never triggered. I hope this helps.

    Femi

  12. Femi

    Correction: I just saw that my href was automatically formatted :-D Shd hv…
    it was supposed to be

    [-a href=”http://localhost/index.php?p=articles&a=view&id=3″ onclick=”return showInfo(‘articles’,’view’,’3′);”-] View full article [-/a-]
    You’ll need to do something similar for form submissions
    Right! Femi
    ——-

  13. Femi

    Lastly about the second question:
    …Also what you do with back button, hash?, frame?, how?!?

    You could have a look at dhtmlHistory, it provides DHTML history, history data, and bookmarking for AJAX applications. It handles the back/fwd buttons quite well and even browser reloads. I’m using that, and it works for me. Cheers
    Femi

  14. Joshua Eichorn Post author

    Femi: we even ship DHTMLHistory with HTML_AJAX it just hasn’t been integrated in anyway. Right now fully integrated support is set for after the HTML_AJAX 1.0 release

  15. Femi

    Hi,
    I’m back again :-D, right? Two things:[1] Actually, I was wondering if there was anything you feel openly I could contribute to this project, not that I’m the best php/js programmer there is, but I could try my hands on a few….
    2ndly, with HTML_AJAX.formSubmit(form,target,target), how can I capture the results from target and directly hand it over to a function, say handleResult, so that i can make it like this?
    HTML_AJAX.formSubmit(form,target,{callback:handleResult()}
    I thot about temp. replacing the target and retrieving the content from there, but Is there a better way?

  16. Joshua Eichorn Post author

    Femi: Improving documentation on the wiki would be a great help. Just sign up on the mailing list and we can go over areas that need improvement.

    For a custom handler on formSubmit using the options array is a good approach.