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.
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>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.
0
elepilAuthor Commented:
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?
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>If you wanted to make your .ajax() call synchronous instead of asynchronous, all you'd have to do is add:

Yes, however, I don't know when I have used ajax in that manner.  

Using post/get or ajax, there is no right or wrong answer if what you are doing works correctly.   Any answer to your question is going to be a matter of opinion.    

I think the real question is not do you use jquery get/post or ajax, it is do you use jquery or angular or knockout or any of the mv js libraries.  http://todomvc.com/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
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.

In answer to both your questions it will depend mostly on your server script (API) and what it's expecting.  Most APIs are written expecting either a GET or POST request and returns data in a certain format.
If it's expecting a GET request then I use GET and vice-versa with POST.  If these aren't going to change and it's simple then I use the shorthand methods.  
In regards to a "preferred method" I think it's as simple as use the shorthand methods where you can (makes your code easier to read) and where the process implies what you're doing.  When there is something a little more complicated or outside a GET or POST, such as "I need to POST data but a JSON object is returned" then I have no choice but to use ajax().
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.