Jump to content
.josh

IF YOU HAVE AN AJAX QUESTION...

Recommended Posts

...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! 

 

In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it).  Or...someone is trying to build their own framework.  That's it!  IMO there has been no other reason worthy enough to warrant not using jQuery or the like!

 

"It will bloat my website, increase page load time, blahblah" is not a good enough reason!  These frameworks are compacted and browsers will cache them!

 

So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?"

 

Seriously.  It is super easy.  Way easier than that code you're trying to post.  Save yourself the headache.  Get jQuery or similar.  DO IT.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Lol first impression was "who the hell is starting yet another thread in caps". But I think many people here agree on what you just wrote. I don't even bother reading vanilla js doing ajax stuff.

  • Like 1

Share this post


Link to post
Share on other sites

Agree 100%.  There is no reason to reinvent the wheel, not to mention the built in cross browser compatibility of most JS frameworks.

Share this post


Link to post
Share on other sites

TY crayon, i wasn't even aware jquery offered this. Was planning on learning this today  8)

Share this post


Link to post
Share on other sites

TY crayon, i wasn't even aware jquery offered this. Was planning on learning this today  8)

JQuery is my only reason for learning any of it. :P

Share this post


Link to post
Share on other sites

I don't agree with that. Heres a very good reason, jquery or other frameworks do not offer certain things i need to create, that require bare javascript (like the realtime password cracker for my game), for someone new to javascript this is bad, i will tell you why, when i go to create a project i utilize all the things i have learned in my years of programming, and with that knowledge i can create marvelous things. But when a new person starts learning javascript through jquery ... they will always program in the lines of what jquery can offer and never anything exciting or something never seen before. As a programmer of many years you must understand, of course it is comfortable for people like us to use a framework, because its not limiting our horizons, its speeding up our work.

  • Like 1

Share this post


Link to post
Share on other sites

This thread is not meant to promote using frameworks instead of using core javascript for everything.  That is just silly.  Frameworks are not alternative languages, they are tools built on existing languages to make certain things easier.  This thread is about using a framework for AJAX specifically. 

Share this post


Link to post
Share on other sites

I couldn't agree more.  I get turned off by Javascript mainly because of the cross browser incompatibility issues.  Well since I started using jQ, life has been alot easier.  I initially resisted learning jQ because I didn't see the point of adding yet another language in my arsenal of programming tools, but after I got really frustrated with using bare jS, I changed my mind, and now I realize that the more tools you have, the easier it is to accomplish any given task.

Share this post


Link to post
Share on other sites

I don't fully agree, although I fully appreciate jquery and it's application, it's just not something that I enjoy using. 

 

While JQuery has an impressive library in terms of quantity, depending on how much customization you require on your website, functionality maybe limited thus using raw javascript maybe inevitable in some cases.

 

The JQuery javascript file is required to run JQuery commands, while the size of this file is relatively small (25-100KB depending on server), it is still a strain on the client computer and maybe your web server as well if you intend to host the JQuery script on your own web server.

 

I think users of jquery should always try to analyze the task at hand before choosing whether or not to use it.  Sometimes the advantages will be greater than disadvantages, but of course this will be reversed in other cases.  I'd rather my website was efficient to use than have jquery doing everything just to make my life easier at the expense of the user experience. 

 

There's a time and a place for everything, and that includes jquery.

Share this post


Link to post
Share on other sites

People always say why reinvent the wheel? The best answer to that, because by reinventing the wheel you understand it better. Rather than just use JQuery to get the job done by writing the whole thing yourself in javascript you're much better off understanding it.

Share this post


Link to post
Share on other sites

People always say why reinvent the wheel? The best answer to that, because by reinventing the wheel you understand it better. Rather than just use JQuery to get the job done by writing the whole thing yourself in javascript you're much better off understanding it.

Yes, that has already been pointed out in the initial post.  I think everyone saying "why reinvent the wheel", including myself, are referring to people that are using raw JS for those reasons.

Share this post


Link to post
Share on other sites

Amen. However, there are bugs in some of the jquery methods. (I.E. when fast hovered, show() starts looping endlessly, even in big sites like Mashable - photo viewer)

But for Ajax, I don't see a reason to use ol' Javascript at all!

Share this post


Link to post
Share on other sites

...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! 

 

In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it).  Or...someone is trying to build their own framework.  That's it!  IMO there has been no other reason worthy enough to warrant not using jQuery or the like!

 

"It will bloat my website, increase page load time, blahblah" is not a good enough reason!  These frameworks are compacted and browsers will cache them!

 

So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?"

 

Seriously.  It is super easy.  Way easier than that code you're trying to post.  Save yourself the headache.  Get jQuery or similar.  DO IT.

 

 

I am sorry, but just because you use these frameworks doesn't mean that everyone who do not use them are stupid like you are trying to imply.

 

You are just another soldier in the "we use frameworks" army. I am a soldier in the "we do not use frameoworks " army

 

Let's keep it civil...

Edited by Stefany93

Share this post


Link to post
Share on other sites

I am sorry, but just because you use these frameworks doesn't mean that everyone who do not use them are stupid like you are trying to imply.

 

You are just another soldier in the "we use frameworks" army. I am a soldier in the "we do not use frameoworks " army

 

Let's keep it civil...

Do you even get his point?

 

Ajax is frankly said easiest to use with a framework...

 

The developers do not have to make their work harder than it is when they can easily use premade stuff.

So, assume this, because I use phpMyAdmin and don't hardcode all tables myself, that makes me a framework soldier? 'k.

Share this post


Link to post
Share on other sites

I am sorry, but just because you use these frameworks doesn't mean that everyone who do not use them are stupid like you are trying to imply.

 

You are just another soldier in the "we use frameworks" army. I am a soldier in the "we do not use frameoworks " army

 

Let's keep it civil...

It was not my intention (nor do I think I implied it) to say you're stupid if you don't use a framework. I said do yourself a favor and make your life easier.

 

Also, I am not "just another soldier" in the "we use frameworks" army. I actually actively resisted and opposed frameworks for a very long time. I too made arguments such as "If people learn jQuery, they won't learn the core language and therefore they will be weak." But the bottom line is that there's always going to be a certain amount of coding involved to keep things cross-browser compatible.

 

And after several years of developing and maintaining my own baked framework (because that is essentially what you wind up with), I came to the realization that there's a whole lot of people out there much smarter than me who are dedicated to maintaining frameworks such as jQuery, vs. just myself, and on my very best of days my code will look very similar to theirs anyways. In short, I came to the realization that it was a waste of my time trying to develop and maintain my own baked framework, because my coding career does not revolve around that framework.

 

Now, I still agree with the notion that one should take the time to learn javascript without frameworks, before diving into using them. I still absolutely agree with the dangers of not properly learning the nuances of javascript if you don't. And the same can be said for any language and framework. But if you've reached that level of expertise, all you are doing is holding yourself back by dedicating time and effort to maintaining your own baked solution. There's basically no compelling argument to do it, unless you are looking to distribute it and focus solely on it.

 

Literally thousands of sites and coders out there developing, testing and submitting feedback etc. to a framework will always do it better than you, one person, trying to basically do the same thing on your own. And for what? Bragging rights? If I'm "just another.." then tell me, what makes you think rolling your own is better? I honestly want to know, because as I said, I did start on your side of the fence.

 

Anyways, I also agree that there's little point in using it if you're only going to use like 1 tiny piece of it. I suppose I will concede that maybe I should amend the OP to weigh the options. But thing is, 9/10 times I see people not using a framework for stuff like AJAX.. turns out the site they are working on is already using a framework. This certainly comes up a lot more for freelancers and coders working in agencies who work with many clients on many sites and it's constantly new sites/clients in the door, vs. some coder working as web dev for a single company. Point being that if you get hired by a client to do some work on their site, it is better to evaluate what they already have going on there and use what's already there, than to just start throwing your own stuff into the mix. If you want to talk about unnecessary bloat, well that's a prime example right there.

 

P.s. - telling me to "keep it civil" right after you've thrown out a "you're just another.." statement.. classy.

  • Like 1

Share this post


Link to post
Share on other sites

Unless the jQuery is also used to accomplish matters that cannot be accomplished with native JS, or that would otherwise require extensive or complicated coding, I see no reason to use jQuery for Ajax calls. IE8+ and all other browsers support the standard XMLHttpRequest(). And what is so difficult about this: 

function updateContent(container) {
    var ajaxRequest = new XMLHttpRequest();
    ajaxRequest.onreadystatechange = function() {
        if ((ajaxRequest.readyState == 4) && (ajaxRequest.status == 200)) {
            document.getElementById(container).innerHTML = ajaxRequest.responseText;
        }
    }
    ajaxRequest.open("GET","new_content_file.php",true);
    ajaxRequest.send();
}

See also http://toddmotto.com/is-it-time-to-drop-jquery-essentials-to-learning-javascript-from-a-jquery-background/.

Share this post


Link to post
Share on other sites

Frank, that's not a fully cross-browser compatible version of ajax for <IE8. Most people still strive to support IE6 and IE7, even though Microsoft stopped officially supporting those versions (and IE8) earlier this year (April 2014 - XP no longer supported, so by extension <IE9 no longer supported).

 

Also sidenote: you gave a simple example of what to do with the response. That example isn't cross-browser compatible either. And in reality, most people use ajax in conjunction with more complex code, from event handlers to selectors, notwithstanding applying previous stuff to whatever dynamically generated content is likely to come from the ajax call. All of that stuff must be applied in a cross-browser compatible way.

Share this post


Link to post
Share on other sites

Josh,

 

I don't believe for a minute that most webmasters still strive to make sites suited for IE<8. And those few who still do should think again. Users with IE<8 can easily upgrade to 8, even have to actively stop Windows (XP) Update from doing so.

 

IE8, and all later IEs, default to Compatibility Mode/View (= IE7) in case of intranet sites, so there is no reason whatsoever for them not to upgrade. And for the 50 users around the whole world who cannot because their company intranet site only functions well in IE6,  there is always FF and Chrome. Even their latest versions run perfectly well on Windows XP. Which they already have installed anyway, because plenty of internet sites do not function in IE6/7 anymore.

 

So, a simple alert for IE<8 users suffices. Keep it simple. And keep it economical for the clients, because making a site suited for IE<8 probably doubles the cost, and/or hampers the possibilities severely. Most certainly when it comes to IE6.

 

With regards to the implementation of the responseText, I guess you are referring to the innerHTML? If so, that makes no difference. jQuery cannot make IE<10 insert/modify <option>s in a <select> either (the famous DOM child update problem that IE<10 has with nodes that standard have children). And there is a simple non-jQuery solution for that: put the <select> in a <span> or <div>, and update the whole <select>. Also, using outerHTML works as well, also in IE8.

 

Still no need for jQuery, therefore.

Edited by Frank P

Share this post


Link to post
Share on other sites

a) Let me remind you that you are responding to a post that was posted several years ago, when this stuff was a much bigger issue.

 

b) I work in the web analytics industry. I look at web stats all day long. And I talk to corporations all day long about those numbers vs. their web sites and the user experience (UX) of their sites. What I see is the exact opposite of your thoughts about webmasters still striving to cater to <IE8.

 

I have been fighting for clients to ditch IE6/7/8 support for years and they are only just now starting to come around since earlier this year, only because of Microsoft ending support for it. So the ball is rolling, yes, but I'm sorry, I disagree with the notions that web devs are in a place where they can just completely forget about supporting it.

 

If you don't believe people are still catering to IE6/7 then I don't believe you have much experience dealing with corporations, and possibly even clients in general. I don't doubt for a second there are plenty of random no-name sites and even some "cutting edge" sites that are "with the times" and cater to younger crowds. And of course it's easy for people to upgrade. And of course there's no reason for them not to. But the stats show that there's still a fair chunk of people that don't, and nobody wants to throw away potential revenue, even if it's 1% of users.

 

Also, I'm not saying there isn't a non-jQuery or non-framework solution for things. That's just silly. All I'm saying is when you have a complex site doing complex things, and having to deal with making sure it works for the widest audience possible, you will more often than not save yourself a lot of time by using a framework like jQuery.

 

Look, I'm done arguing with you about this. As I mentioned in a previous post, I used to be hardcore on the other side of the fence, absolutely shunning frameworks as extra bloat used by people who can't be bothered to learn "real" javascript. I know exactly where you're coming from because I've been there, so I know there's little point in trying to argue with you about it.

Share this post


Link to post
Share on other sites

Josh,

 

There are gentler ways to win an argument than bullying ("I don't believe you have much experience dealing with corporations, and possibly even clients in general"). Such as with valid arguments that have weight. Which I don't see in your reply. 

 

First of all, I'm working on IT projects that are probably way out of your league. The fact that I don't have time to make websites for small business and private parties doesn't mean that I wouldn't know what I'm talking about. The other night I solved a layout problem on Stack Overflow that nobody else knew how to solve. A question that was posted by one of the SO moderators, and that got a bunch of up-votes and favorite-question stars in no-time.

 

Also, simple logical reasoning disproves your basic point, even if I would be a novice. Nowadays, there are only two kinds of users who still have IE6/7. The first kind is the people who still have a Windows 95 computer. I don't think any webdev in their right  mind would wanna code for them. The second kind is the employees of large companies with XP computers, obliged to use it for their intranet sites. Not much wrong with that, but they won't use that same IE6/7 for the internet sites they visit. Simply because they've learned that those sites are not functional anymore with such an old browser. They will get alerts all the time, and will use FF or Chrome, which they have will have installed on their computer as well. 

 

Those large companies have their own IT staff, making their own intranet websites. I don't think many PHP Freaks webdev-visitors will be asked by such companies to make a site for them. In fact, I would think the number is zero. Apart from you, maybe.

 

Furthermore, the (American) stats on http://gs.statcounter.com/#browser_version-US-monthly-201305-201405 show that even IE7 has left the building. And which corporations are you referring to that have sites that need IE6/7 to be functional and esthetically appealing? Unless you have a time machine, I don't think there are such corporations anymore. N=0, again.

 

Nonetheless, I wanna make friends with you. How about if I write a tutorial for PHP Freaks, explaining the basics of modern Ajax, including the pitfalls regarding the implementation of the responseText, which there still are a number of? I'll do it for free.

 

Just think about it. But even if you reject this offer, you still have to delete this whole thread. Because what you are stating in your original post translates to "If you don't use layout tables, don't come asking here for advice" on the CSS section of PHP Freaks. Time to upgrade, Josh.

Edited by Frank P

Share this post


Link to post
Share on other sites

Frank,

 

I concur with .josh's original post. I think you are reading something into the post that isn't there. He never stated that you can't implement AJAX without a framework. He was only stating that if you are asking for help with your AJAX implementation be prepared to be asked why you are not using a framework.

 

Why? Because the vast majority of the people asking for help on this forum are novices. These are the people that typically get shunned in other forums because they really don't know what they are doing. These are people that may struggle with creating a simple script to query a database and generate output. AJAX is not rocket science, but it is not something the uninitiated really grasps out of the box. Trying to help someone debug issues with AJAX can be very complicated because of all the different technologies that are typically involved: PHP, MySQL, JavaScript, etc. By using a framework we don't have to read through all of their JavaScript to see if the person wrote wrote the handler correctly or not. It helps to reduce a point of failure that happens all too often. For someone that really knows what they are doing - by all means they can and should write the AJAX code to their specific needs. But, these are also the people that wouldn't need to come and post on a forum for help with it.

Share this post


Link to post
Share on other sites
Posted (edited)
On 7/13/2011 at 3:58 AM, runthis said:

But when a new person starts learning javascript through jquery ... they will always program in the lines of what jquery can offer and never anything exciting or something never seen before.

That is a fundamental difference in the abilities of the programmer. Some people can program well in a language but cannot think outside the box of their language, then there are those who can program INTO a language and do things that otherwise could not be done in that language.

As an example (a poor one maybe) I have a Texas Instruments TI-NSpire CX CAS calculator, the TI-Basic has no class or includes capabilities so I took the time to write wrappers that allow me to mimic these abilities in the calculator. 

Thinking outside the box is what separates the programmer from the person who just plays around.

Edited by Karaethon
Accidently hit submit before finished typing.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.