ASK – AJAX Source Kit

Updated February 17th

Denny brought to my attention that the history and the links didn’t work flawlessly if you have the same target element for several ASK links. Therefore, I’ve now added a paremeter to the object constructor, this.useSameTargetForSeveralCalls = false; that should be set to true if you want to use the same target element for several ASK links. However, the default value is false to avoid adding links to the history if they have different target elements, and also to save performance.

Updated September 29th 2006

I’ve updated a more fail-safe way to use the XMLHTTP ActiveX object in IE, and also added proper fallbacks if the first one fails.

Also, a very minor change has been done to the event handling to cover up for a bug in IE’s garbage collector (something I hear will be addressed automatically in IE 7). In 99,9% of the cases you won’t notice any difference, but if you use it in a very advanced web site/web application it might make things better and less resource intensive.

I have always liked the approach of updating certain content on-the-fly in a web page without the need of reloading the entire content. This approach has been around for years and has fairly recently been nicknamed AJAX.

The thing with AJAX is that it needs JavaScript to work and a direct consequence surrounding its hype is that a lot of web sites have implemented it without catering to common usability and accessibility factors. This is something that has saddened me, and therefore I developed ASK – AJAX Source KIT to address that while at the same time offer a light-weight library to implement AJAX functionality without having to worry about web browser differences.

The basic idea of it is to implement AJAX without sacrificing those factors and at the same time do it in an unobtrusive way, meaning that there’s no need for any event handlers or extra elements in the HTML code. All that is needed is to include the ASK JavaScript file, assign certain class names to the elements one wants to apply the ASK functionality to, and then implement accessible as well as AJAX-enhanced versions of the content that shall be retrieved dynamically.

My ASK concept was featured in the February issue of Treehouse Magazine, where you can find a more in-depth explanation of the code and about the choices I made during its developing phase.

I should also mention that it was inspiring to read Fixing the Back Button and Enabling Bookmarking for AJAX Apps and AJAX: How to Handle Bookmarks and Back Buttons to see the problems they ran into and how they dealt with them, and then take it a notch further.

My humble hope is that by seeing this, more web developers will understand what it takes to take a considerate approach to AJAX while using it to offer end users a richer experience. Please try it out and don’t hesitate to post any questions here that you might have.

Links

81 Comments

  • Hakan Bilgin says:

    Robert,

    The solution is very cool, respect…

    A relating topic, what is your opinion on how far or back one should support compatibility? The quantity and versions of browsers doesn't decrease, on the contraty it's increasing fast. With each release of a browser, changes made to the broswed convey in differing interpretations. With such environment, the risks for errors/missinterpretations grow exponentialy.

    Ok, this is why there are standards, but the standards are changing as well, which seasons the soup. Many advocate support and following standards, but at the same time this convey in solutions that looks and feels the same everywhere, because "multi-support" results a limited space for exploration (hope you agree with this last claim).

    Perhaps off-topic…

    Once again…ASK is great…kudos

    /hbi

  • Rimantas says:

    Oh, browser sniffing…

  • Robert Nyman says:

    Hakan,

    Thank you!

    It's a very interesting thing you mention and I've been thinking about writing about something like that for a while. Is it ok if I can say that I will get back to you on that with a post later on?

    Rimantas,

    Trust me, I'm all for object detection. But in this case it wasn't sufficient when it came to two cases:

    1) Opera claiming to support <code>document.all</code> but not handling history the same way IE does.

    2) Knowing that a certain feature wouldn't work in version 5.0 in IE, thus turning that one off.

    If you're more interested in my take on object detection, please read Object detection.

  • Seems like a very good AJAX framework to me. I keep seeing AJAX apps that don't handle bookmarking and the back button like it should, this makes it easier for people to do things "the right way". Well done!

    Worth a note is that a non-js version of the content is needed for accessibility and search engines. Two not so trivial bad things about AJAX.

  • Robert Nyman says:

    Emil,

    Thank you!

    One of the major ideas with my implementation is that the default approach is to offer an accessible version as well, and I also add a parameter to the querystring when an AJAX call is made.

    So, in the end, it's all down to the final implementator of this solution to indeed offer an accessible version as well, one that will also address the search engine issue at the same time.

  • I always thought about doing a bookmarking, history module, but never had the right application for it, so kudos to you.

    I'm wondering though, if you have several consecutive ajax calls which affect the page, and which can theoretically be a random selection from a number of actions by the user, how do you bookmark that page so that the series of events is replicated just by going to a single URL?

  • Mantroniks says:

    thought to share an article regarding async calls …

    http://www.hedgerwow.com/360/ajax/latency/demp.ht

  • Robert Nyman says:

    Cameron,

    Thanks for visiting, and thanks for the compliment!

    If you bookmark a page when you've made several calls, and then navigate back to that page using the bookmark, it doesn't just make one call to a single URL. What it does is repeating the same calls as when you clicked the links, in that consecutive order.

    Mantroniks,

    Thanks for sharing!

    Since I cancel ongoing AJAX calls if a new one is made, naturally retrieving that data is cancelled; same thing happens if you click a link in a web page and then another in the same page before the first one has loaded.

    Douglas,

    Thanks! πŸ™‚

  • Wow Robert. You're really sharing too much of your kindness with us! πŸ˜‰

    My experience with AJAX is minimal, but I've always felt that fixing bookmarking and history is an absolute requirement for such solutions. It pleases me to see you tackled that problem and I am looking forward to using it somewhere soon.

    You rock. Keep up the great work!

  • Robert Nyman says:

    Jeroen,

    Thank you very much for those kind words! πŸ™‚

  • Aldrik says:

    Wow….! Very nice, I’m considering using it on a revamp of my families company site (it’s cirrently using frames ewww) I’m currently working on.

    Q: Where dose the “Concept and code by Robert Nyman” (& site) need to be included? On every (x)html page that uses it or just in the javascript file? Not that I dont wanna give you credit πŸ˜‰ I’d just rather do it a web development/design page when I get around to makeing one.

    PS. Where’s the link to join the Robert Nyman fan club?

  • Robert Nyman says:

    Aldrik,

    Thank you very much! πŸ˜€

    You only need to include the copyright statement in the JavaScript file, don't worry. πŸ™‚

  • Matthijs says:

    Robert, thanks for sharing this. I read your article in particletree as well and must say this looks very interesting. Funny thing is when I first tried the demo I was thinking: "nice, but how do I remove the added lists again?…" But then I pressed the back-button and voila! πŸ™‚

    There's so much to do with ajax, there are many demo's, scripts and complete libraries out there. But most of it is just "cool stuff", totally forgetting accessibility, usability and good coding practice (seperating layers etc). But I have a feeling I just found something realy useful.

  • Robert Nyman says:

    Matthijs,

    Thank you!

    My hope and goal is to target those specific things you mention, to do it in a proper way.

  • Denny Carl says:

    Robert, this is a really nice and interesting approach to include AJAX on a website, which even respects browser history and bookmarking. I think, I've never seen an easier way. Probably every webdesigner who barely knows some tags of HTML will be able to use AJAX soon πŸ™‚ Thank you so much for sharing this.

    I've played a bit with ASK and now, I have following question: Imagine, at your demo site continents, countries and cities have the same target-div. Now I click on continents, then cities and then continents again. IMHO, the last step doesn't succeed. Is there a way to solve this problem?

  • Robert Nyman says:

    Denny,

    Thank you very much!

    The history feature apparently didn't work flawlessly if you have the same target div, i.e. not getting the correct content when having the same target element. Thanks for getting this to my attention!

    I have now added a paremeter to the object, <code>this.useSameTargetForSeveralCalls = false;</code> that should be set to true if you have the same target element for several ASK links. However, the default value is false to avoid adding links to the history if they have different target elements.

  • […] of good work is going on in that direction. Recent work by the likes of Mike Stenhouse and Robert Nyman is showing us the way. Some people are advocating that we should get scre […]

  • Mike says:

    It is amazing to see the back and forward history working, but I am still wondering will there be a link pointing to the current page? I mean what if I want to send the hyperlink to a friend without an ajax-functional browser? http://www.robertnyman.com/ask/content.php#2:1
    doesn't redirect him to the page I am seeing.

    Sorry for my bad english.

  • Robert Nyman says:

    Mike,

    Thank you!

    It's a very valid question, and I'm not really sure how that would be solved. To me, if you're using a web browser which supports AJAX and sends a link to a friend who has a web browser that doesn't, I guess I personally regard it "good enough" that they just get to the start page of the web site in question then.

    If you indeed want to cover up for that, I guess there has to be implemented some kind of logic on the server-side in the receiving web page that then redirects you to the correct web page with the correct options.

  • Mike says:

    I have got another problem with the ASK page: My forward function become unfunctional when browsing back to the ASK page, i.e. my forward history seems lost.

  • Robert Nyman says:

    Mike,

    This is something that has to do with IE only, and it's a side effect of how anchor navigation is handled in IE. Unfortunately the <code>iframe</code> trick to fix the navigation doesn't work for that scenario.

  • Mike says:

    Actually I am using the lastest firefox release 1.5.0.1, but still have this kind of history problem.

  • Robert Nyman says:

    Mike,

    Ah, I see. Interesting. I'm not sure why this happens, because all the script does is updating the value in the <code>location.hash</code> part of the URL. Maybe the web browser then sees this as a manually entered URL that forfeits your previous forward step.

  • Aarron says:

    I have been digging through the mounds of AJAX libraries as of late, and ASK is by far the easiest to use. Just what I was looking for, power with no bloating.

    I was wondering if there is some way to implement a loading message when waiting for content from the server.

    Thanks for sharing!

  • Robert Nyman says:

    Aarron,

    Thank you, I'm glad to hear that!

    To display a loading message, you can just tweak the function <code>AskGetContent</code> any way you like, it's from there the actual call is being made.

    Good luck! πŸ™‚

  • Aarron says:

    I ended up doing this to get a loading message to work correctly:

    <pre><code>

    function AskGetContent(oLink, bHasCachedContent){

    this.currentLink = oLink;

    var strURL = this.currentLink.getAttribute("href");

    this.currentLinkURL = strURL + ((strURL.search(/?/) != -1)? "&" : "?") + this.urlExt;

    this.elmToPresentIn = document.getElementById(this.currentLink.className.replace(/.*target-([wd-]+)(.*|$)/i, "$1"));

    if(!bHasCachedContent){

    this.createXmlHttp();

    this.xmlHttpCallComplete = false;

    // LOADING MESSAGE

    ask.elmToPresentIn.innerHTML = "Loading …";

    this.xmlHttp.onreadystatechange = function (){

    if(ask.xmlHttp && ask.xmlHttp.readyState == 4){

    ask.presentContent();

    }

    }

    this.xmlHttp.open("GET", this.currentLinkURL, true);

    this.xmlHttp.send(null);

    }

    else{

    this.presentContent();

    }

    }

    </code></pre>

    I tried putting the loading message in a conditional to only show it when the ready state was not 4 (not done loading), but the loading message only blinked on for a split second after the content had loaded.

  • Robert Nyman says:

    Arronn,

    I'm glad it worked out well for you! πŸ™‚

    The diferent switchings between ready states are always interesting to see, when they decide to take place and such… πŸ™‚

  • naden says:

    First of all, it's a very nice ajax lib, very easy to handle.

    I used it in a project I'm currently working on and came across the problem, that I have to initialize the part I like to alter with ajax on page creation to give the user something to see.

    Therefor I corrupted you code ;| and added two extra methods "mygetContent" and "mypresentContent". It's a fast and dirty but working hack. I just stripped of some of your code like the caching …

    For the forward and backward navigation I used your code as you intended.

    I included ask.js on to of the page and put the following snipped inside the html.

    <code>/// my init call, use the same url as for onclick later

    ask.mygetContent('/ajax/mygetdata.php?user_id=123', 'mydatasection' );</code>

    MyAskPresentContent

    <code>function MyAskPresentContent(){

    if(this.xmlHttp){

    this.responseText = this.xmlHttp.responseText;

    }

    this.elmToPresentIn.innerHTML = this.responseText;

    this.addEvents(this.elmToPresentIn);

    this.clearXmlHttp();

    }</code>

    MyAskGetContent

    <code>function MyAskGetContent(oLink, el_id){

    this.currentLink = oLink;

    var strURL = oLink;

    this.currentLinkURL = oLink;

    this.elmToPresentIn = document.getElementById(el_id)

    this.createXmlHttp();

    this.xmlHttpCallComplete = false;

    this.xmlHttp.onreadystatechange = function (){

    if(ask.xmlHttp && ask.xmlHttp.readyState == 4){

    ask.mypresentContent();

    }

    }

    this.xmlHttp.open("GET", this.currentLinkURL, true);

    this.xmlHttp.send(null);

    }</code>

    I guess if you add these feature and the loading message Aarron mentioned. It's worth to call it ask 2.0.

    regards Naden

  • Robert Nyman says:

    naden,

    Thank you!

    As I understand it, you want to prefill some element with the content as soon as the page has loaded? While I definitely understand the usefulness of such approach, it doesn't go in line with the accessibility part of ASK. A user should be able to see all of the content with or without JavaScript enabled. Therefore, I'm hesitant to adding it to ASK…

    Arrons example with a loading message is more like a progressive enhancement thing, to show a simple loading message to those that support it, as opposed to your idea with actually retrieveing actual content.

    All in all, though, I don't want to add anything to ASK just for the reason to keep it light-weight and try to avoid it getting bloated as most JavaScript libraries in the market. Many people use it for very different needs, so I'd rather say it's up to them (exactly as you did) to tweak it for certain cases. I hope you understand what I'm going for… πŸ™‚

    I guess the best approach would be not to touch the original libary's code but instead add extra JavaScript files with desired overriding and/or additional functionality.

  • harald says:

    hi,

    thanks for this frame work. i like it.

    there is a bug, on the ie explorer.

    on the demo page open "get continents" push the back button and realod the page. after this it's not possible to use the side. delete the # or push reaload again.

    second i wrote a side using the ask and it's fine with firefox but not with the ie. πŸ™ are there some special requirements ?

    then a wish : is it possible to set a environment variable to enable/disable the history feature ?

    many thanks

    harald

  • Robert Nyman says:

    harald,

    Yes, if you do it in that exact order, history handling seems to bug out in IE. Not sure why, I guess it's because the history handling is faked through an <code>iframe</code> and for some reason it loses context if you do it like that. As of now I have no solution for it.

    No special reguirements, it should work fine with IE as well. Please download the demo package and test it.

    When it comes to disabling history, I don't want to add that. The reason is that I want it, per default, to work as much as a normal web site as possible, meaning that the back button works, that you can bookmark a certain state of the web page etc.

  • harald says:

    normaly ie works. but in some cases it does not. also in firefox i have some strange things with the ASK framework. i think it is importend to fix this bugs and make ask 100% stable. i'm sorry i'm not a javascript developer.

    thats why i'm asking for a switch like useSameTargetForSeveralCalls also for the history.

    so that the webdeveloper is able to say how the site is handled. for some php sites it is not the idea to bookmark a certain state of a side.

    thanks for your quick awnser

  • Robert Nyman says:

    harald,

    I'm sorry, but for the moment I don't know how to, nor have the time, to solve the problem you have in IE.

    When it comes to the history, I don't think that it should be an option in ASK not to have history; not having history ruins the gist of the idea behind ASK. Can it be done? Absolutely, but I think it would take a little time.

    I only offer a basic framework for people to use and adapt. If you want to do anything different that I don't think should be in the basic framework, then it's unfortunately something you have to do on your own, alternatively ask some of your friends/colleagues.

  • Robert Nyman says:

    harald,

    I’m sorry, but that’s the default behavior so you can still go through the history for each click you made.

  • harald says:

    last point.

    if i use useSameTargetForSeveralCalls to open some links

    then reload the site with the browser button, the hole history is reloaded, not only the last one….

    may fix this ?

    thanks

  • Jon says:

    Great product, works nicely. However, for some reason the character encoding is messed up and the result is no longer ISO-8859-1. I've used some other AJAX toolsets in the past, and they had encoding settings – does ASK?

    Pros with your solution is the way AJAX calls are triggered – with traditional href links – so turning AJAX on/off is simple and it will work the "old" way.

  • Robert Nyman says:

    Jon,

    Thanks!

    Don't have any direct idea why the character encoding would get messed up. I guess it's just a matter of settings on the server.

  • Liutauras says:

    <blockquote cite="harald">

    if i use useSameTargetForSeveralCalls to open some links

    then reload the site with the browser button, the hole history is reloaded, not only the last

    can be here any hack to load just last page and ignore others?

    if it can't be done, maybe it is good to make history deep parameter, what is Your opinion about that?

    Thnx!

  • Robert Nyman says:

    Liutauras,

    You're free to make any changes to the library code, but I personally don't plan to make any more additions to the library in the near future.

  • Hej!

    This article on AjaxPatterns describes the problems and solutions you have already provided an answer to with ASK.

    In case you haven't read about it, I suggest you go ahead and link to your source kit for you certainly know it and talk about it better than I.

    Ha det så bra!

  • Robert Nyman says:

    Hej Goulven!

    Thanks for the tip, I added a link to ASK to the list of available resources.

  • Thanks Robert. After weeks of searching, I think ASK may very well be the holy grail I've been looking for! Works like a charm in all the browsers I tested.

    Anyway, I would like to know if ASK supports sending variables via Forms ? So far in going through your code, I see the only way to send variables is through href link tags. I'm not very experienced in advanced coding so perhaps I am missing something?

    I'd like to have forms so users can input multiple variables and generate content based on those variables, with only one click. And also so they can edit those multiple variables all at once, and then resend to regenerate new results.

    It's great to see how you've taken time to address everyone's comments, we are very much appreciative indeed. Thank you.

  • Robert Nyman says:

    Jade,

    I'm happy that you like it!

    It's a tricky question you have… Not sure if it can be done easily, you need to do some tweaking to make that happen, and to be able to apply the ASK event to the submit button of the form.

    First, in the <code>AskAddEvents</code> function, you need to change this line:

    <code>var arrAllAJAXLinks = getElementsByClassName(oContainerElm, "a", "ask");</code>

    to:

    <code>var arrAllAJAXLinks = getElementsByClassName(oContainerElm, "*", "ask");</code>.

    After that you need to change the <code>AskGetContent</code> funtion to check what element it is, and then instead of checking the <code>href</code> attribute, you need to find the submit button's containing form and then loop through all of its elements to apply each element's value to the query string and then make the request.

    I hope this short description helps, unfortunately I don't have time to code it.

  • congtq says:

    hi, ASK is nice ! A websie even can run when disable Javascript.

    But I look for a problem: When view source on bowser, it can't view source (HTML)

    Then I have a question: Could Search Engine find my site ?????

    Thanks !

  • Robert Nyman says:

    congtq,

    Since the content is updated on the fly, no web browser shows the updated source; view source only displays what was initially loaded. You can use the DOM Inspector in Firefox to see the updtaded content.

    Regarding search engines: search engines will find your fallback URLs, i.e. the ones that are displayed for non-JavaScript users. Therefore, it is extra important to implement versions of the pages that will work without JavaScript.

  • Rolf says:

    Robert,

    I have been playing with ASK and I think I like it πŸ˜‰

    I am not a very skilled JS programmer, so when going through the source it gets a bit hard for me.. but anyway, I grasp the concept and can work with it.

    One question though:

    Is it possible with the current version to update more that one target divs?

    For example; I have various divs floating on screen and when I click on (let's say) "detailed info" through some link I have to update those several divs. However I can not "wrap" them into one big target-container div or something like that.

    You understand what I am trying to do?

    Regards, keep up with the blog, lovin'it.

    Rolf

  • Robert Nyman says:

    Rolf,

    I'm happy to hear that!

    I understand what you mean, but generally I wouldn't support the idea, unless the link (for people with non-JavaScript support) would update the same parts as well.

    You need to do some serious tweaking to the script, something that I unfortunately don't have the time for. All I can do is give you a pointer: In the <code>AskGetContent</code> method, you need to change <code>this.elmToPresentIn</code> into an <code>array</code> instead and then loop through it in the <code>AskPresentContent</code> method.

  • Demas Sinner says:

    Robert,

    About the back button and AJAX.

    This might be a stupid question, but I have thought about it for a wile so here it comes.

    Is the user expecting to reverse an executed action on the page or is he expecting to be redirected to the previous page.

    I’m not sure.

    But when I hit the back button it makes more sense to jump to the previous page rather than undo the expanding the list of Countries. I’m finding myself clicking the link again in order to make it reverse and hide the list of countries again.

    Any comment on that?

    Thanks for a work well done.

  • Robert Nyman says:

    Demas,

    The idea of the concept is that it should work as normal navigation between differerent web pages; only difference here is that it is navigation between different states of the same web page.

    It is also the cornerstone of being able to link to/bookmark a certain state of a web page, instead of having to redo all the actions again.

    So, basically, you shouldn't regard it as web pages but rather as states. πŸ™‚

  • […] gn of the KTH web site and I did a talk about the foundations of AJAX, and then introduced ASK and also talked about what the future might hold. It felt like both presentation w […]

  • […] struggles… Luckily, this hasn’t happen in some time now, but for anyone using ASK or AJAX-S, bear in mind that some of the core functionally was coded while I was n […]

  • fdh says:

    Hey,

    really nice JS library. I only have one problem with it, I have several links that target one div and I set this.useSameTargetForSeveralCalls=true, but when I browse through my pages the URL looks like this: foo/#1:3:1. When I boomark the page and go to that bookmark, it loads 1, then 3 and then 1 rather than just the last one. Any way to fix this?

    Thanks

  • Robert Nyman says:

    fdh,

    Thank you!

    The way it works, it adds the number to the URL for each click on a link, no matter if that link has already been clicked. This is for forward and back navigation to work properly, but unfortunately it will affect bookmarking they way you describe.

    As of now, I'm not sure how to address that.

  • […] pers have started thinking in terms of accessibility and fixed many of AJAX initial flaws. Nyman’s ASK is one way. Search Engine Optimization (SEO) Poor. Search engines d […]

  • Hi!

    at first: ASK is great! It's simple and it works! Thx!

    And now a Bug report:

    I tried to have the whole navigation ASK-based. It's a combination of left and top navigation the top-navigation loaded via AJAX, too.

    So if I click top-nav #1 it works

    But if I reload the content via left-nav #3 top-nav links #0 and #1 are remapped to #7 and #8 and stop working.

    Is there a way to fix this?

    And concerning the bookmark problem I think I found a workaround:

    I just change in line 93 i=0 to i=arrLinkIndexes.length-1.

    I don't understand much JS, so I dunno if this brings up any new bugs, but at least in firefox it seems to work quite nice!

    It loads the first page once and than the right one.

  • Just tried in IE7: When native XMLHTTP support is activated (default) than nothing happens.

    When I deactivated the support, the core functionality was up again, but the history support was broken.

    (Has nothing to do with my workaround, tested on the unmodified script)

  • Robert Nyman says:

    Christoph,

    Regarding your problem with the navigation: if you have ASK functionality to replace already existing links with new ones, i imagine you might run into problems. I guess the thinking is somewhat reversed; if you have ASK links, why replace them with new ones with the same functionality?

    To answer the question: replacing existing ASK links with new ones probably won't work.

    I've tried ASK generally in IE 7 myself, with the native support, and it works as intended. I guess it's something with your specific scenario that unfortunately breaks the desired functionality.

    I'm sorry I can't help more.

  • First of all, let me say that i love the simplicity of ASK. I use ask to load different content in the same div with different links. I use this.useSameTargetForSeveralCalls = true; which indeed works for me. Only problem that I have with ask is that after clicking on a few links, the url looks like this: #2:4:4:5:2:1:9:3 (or so). That is kinda annoying but not the problem. The problem is when you hit F5 for a page refresh, you see the content in the target div flashing every page from the first until the last one. I beleave the best way to avoid this is just having the last page after the #-sign in the url when using this.useSameTargetForSeveralCalls = true;. It shouldn't matter for the bookmarking and back-bunnon anyway… I bealeave this could also be (part of) Christoph Wagner's problem.

  • Robert Nyman says:

    Erik,

    Thank you, I'm glad you like it!

    That is valid input, and something I should look into. At the moment, unfortunately, I don't have the possibility to put any more time into ASK (although I'd definitely like to). However, a tweak like that sounds fairly easy if that property is set to true, so maybe it can be easily fixed.

    Just not now, though. 😐

  • Shahbaz says:

    Hello Can we some sort of ajax loading indicator in this script.

    Thanks.

  • Robert Nyman says:

    Shahbaz,

    Absolutely, but it's not supported in the core script, so you need to tweak it yourself.

  • Guillaume says:

    Hello,

    You have done a great job with this lib.

    However, I encounter the following problem :

    I setup useSameTargetForSeveralCalls to true, when a page loaded thru ask is put in the target div, the links inside this page with the ask class name works fine. But when I press the back button of the browser, the previous page loaded thru ask with some links inside isn't handle anymore by ask. The onclick event isn't added any more.

    I tried to look thru the code but I don't find how to apply again AskAddEvents…

  • Robert Nyman says:

    Guillaume,

    Hmm, that's a tricky question. If I understand you correctly, you have ASK links within the new content you retrieve with ASK? And that works as long as you move forward, but if you use back, no events are applied?

    I tried that out and your description is correct. What you can do, which should work, is to add one line in the code:

    Line 108, you will find this code:

    <code>document.getElementById(strElmToRemoveContentFromId).innerHTML = this.links[intLinkIndex][2];</code>

    After that, add this line and events should be applied again:

    <code>this.addEvents(document.getElementById(strElmToRemoveContentFromId));</code>

    This is, however, experimental and I can't guarantee that it works consistently.

  • Guillaume says:

    Yes, this what happens.

    Thanks a lot, that solves my issue !

  • Robert Nyman says:

    Guillaume,

    Great! πŸ™‚

  • Shihan says:

    Hi,

    Great work. Though I am basically a jQuery fan for doing ajax or other DOM related JS works, ASK has really impressed me, particularly the very intelligent and functional Back/Forward button's history manipulation.

    Do you think ASK can be integrated with with a jQuery based web app without any conflict?

    One more thing, doing Back & Forward for a few times in IE7 for your demo page, breaks the history maintenance also the ajax functionalities of links where as in FireFox 2 evrything was so smooth & functional. Not sure whether its a particular bug in IE7 or not but would be nice to have it fixed (if possible).

    Hats off again for your great work.

    Regards,

    Shihan

  • Robert Nyman says:

    Shihan,

    Thanks! I haven't really looked at this code in a long time, and I know IE can have some problems with repeated actions.

    I think this should work fine side-by-side with jQuery, although I can't guarantee it. Then, if course, I'd like to recommend that you take a look at DOMAssistant as well. πŸ™‚

  • Shihan says:

    Hi Robert,

    Thanx for your quick response.

    Never aware of DOMAssistant till now. Thanx a lot. Will definietly give it a try. But I think jQuery's plugin-base is now so much stronger than DA, that the performance gain can be compromized for consistency and availablity of a large collection of ready to use codes. Particularly, I'll wait for plugins like form, validate, tab & taconite in DA that I frequently use in my developed apps with jQ.

    Another question, ASK's history support is currently intended to remember just only the content that is added/changed in a single container by a single ajax call. Is it possible to extend ASK's history management (& also how much effort do you think is needed if possible) to remember multiple DOM changes that are performed in one or many containers through a single ajax call (think about using taconite)? I'll hope you are very familiar with taconite though FYI, with taconite architecture its very easy to to perform any kind of DOM modification as a result of a single ajax call through a very manageable way that can be controlled from server side scripts. And also the links are…

    Regards,

    Shihan

  • Shihan says:

    Hi, a small correction in last line of my last post due to misunderstanding of html tag support :

    <blockquote cite="">

    And also the links are taconite & jQuery taconite plugin.

    Regards,

    Shihan

  • Robert Nyman says:

    Shihan,

    Regarding jQuery, and other major JavaScript libraries: they definitely have a large community and there's an abundance of plugins available. However, my hope is that having an efficient and fast core will, in the long run, provide the best ground to build on.

    There's a validation plugin to DOMAssistant in beta, so please try it out if you want to.

    With ASK, it's not being developed anymore, but feel free to tweak it to the needs you might have.

  • […] ASK – AJAX Source Kit – The thing with AJAX is that it needs JavaScript to work and a direct consequence surrounding its hype is that a lot of web sites have implemented it without catering to common usability and accessibility factors. This is something that has saddened me, and therefore I developed ASK – AJAX Source KIT to address that while at the same time offer a light-weight library to implement AJAX functionality without having to worry about web browser differences. […]

  • Stefano says:

    I thank you for the script but was wondering if you can recommend an easy way to make the href="x" where x can be any website not just a path in your website?

  • Robert Nyman says:

    Stefano,

    By default, the security model with AJAX in web browsers doesn't allow you to do cross-domain AJAX requests. In that case, you need to resort to proxy-server or JSON-based solutions with script includes.

  • […] ASK – AJAX Source Kit – The thing with AJAX is that it needs JavaScript to work and a direct consequence surrounding its hype is that a lot of web sites have implemented it without catering to common usability and accessibility factors. This is something that has saddened me, and therefore I developed ASK – AJAX Source KIT to address that while at the same time offer a light-weight library to implement AJAX functionality without having to worry about web browser differences. […]

  • […] ASK – AJAX Source Kit – The thing with AJAX is that it needs JavaScript to work and a direct consequence surrounding its hype is that a lot of web sites have implemented it without catering to common usability and accessibility factors. This is something that has saddened me, and therefore I developed ASK – AJAX Source KIT to address that while at the same time offer a light-weight library to implement AJAX functionality without having to worry about web browser differences. […]

  • […] ASK – AJAX Source Kit – The thing with AJAX is that it needs JavaScript to work and a direct consequence surrounding its hype is that a lot of web sites have implemented it without catering to common usability and accessibility factors. This is something that has saddened me, and therefore I developed ASK – AJAX Source KIT to address that while at the same time offer a light-weight library to implement AJAX functionality without having to worry about web browser differences. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.