Link to home
Start Free TrialLog in
Avatar of elepil
elepil

asked on

Want jQuery opinions on jQuery AJAX

I know one can use .ajax() or use the shorthand methods (e.g. .get(), .post()).

I also know that .ajax() allows you to use TONS of parameters other than just the url or data values you want to pass to the server which the shorthand methods succinctly accommodate.

Question 1: Would I be right in thinking that it would be better for me to get into the habit of using .ajax() rather than the shorthand methods? My reasoning is that with .ajax(), one does have the option of using only the parameters you need (out of numerous) and therefore will be more scalable to your needs. But if you use the shorthand methods and later want to do a synchronous call, you're in trouble because the shorthand methods have no provisions for that like .ajax() does. In this sense, I can't really say it's a matter of "preference" or "taste", right?

Question 2: This is for experienced professional developers. Which is the preferred method out in the real world, is it .ajax() or the shorthand methods? I just wanted to get a feel via  consensus of how professionals do it.

Thanks.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

>I can't really say it's a matter of "preference" or "taste", right?

I think you can.  

I personally use ajax and some form of the example
$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

Open in new window


But like most things in WebDev, there are multiple ways to get to the similar visual output.  And each of those ways will almost always be a good debate.

Your loading the library anyway and I don't believe there are any performance gains using one over the other.
Avatar of elepil
elepil

ASKER

To Scott Fel. Thank you for responding.

You gave me your preference, but I didn't quite get direct answers to my questions.

On question 1, you responded by saying you use .ajax(), but let me pose this question to you. If you wanted to make your .ajax() call synchronous instead of asynchronous, all you'd have to do is add:

async: false;

Open in new window


while you won't have that option if you were using the .get()/.post(), right?

But question 2 is really important to me. Although I have been a professional developer for quite a while now, it hasn't been in this platform. So for employment purposes, I need to get a feel which method is used in greater frequency? So what is your observation?
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial