1

The question pretty much says it all. I'm trying to create a submission form where users can add information to their profile, updating the MySQL database, without page refresh. For example, I want users to be able to add 'hobbies', which is what I'm working on right now.

Well, I'm going through a StackOverflow tutorial, here, and I'm trying to look up each of the functions. Unfortunately, google's not turning up any kind of complete AJAX reference, leading me to believe there isn't one out there. I think AJAX is just the name of something that happens, and it's built into libraries like jQuery? So, how do I figure out what ajaxSubmit() and other ajax-appended functions do?

Community
  • 1
  • 1
Wolfpack'08
  • 3,982
  • 11
  • 46
  • 78
  • 1
    *AJAX* is short for *Asynchronous JavaScript And XML*. W3C compatible browsers (not sure here) implement this with [`XMLHTTPRequest`](https://developer.mozilla.org/en/XMLHttpRequest), whereas IE has an ActiveX object for that. [There is a W3C Candidate Recommendation for `XMLHTTPRequest`](http://www.w3.org/TR/XMLHttpRequest/). – Felix Kling Oct 14 '11 at 07:12
  • 1
    IE has a native XHR now. – Quentin Oct 14 '11 at 08:55

4 Answers4

3

You're right about AJAX not being a specific thing, but a term that loosely describes what is happening. What is normally used is a XMLHttpRequest object (provided by browsers), which allows you to send requests to the server and get their response.

Beware, there are different ways of doing AJAX in different browsers. This is why it's so much better to use a library (such as jQuery) that handles all that nasty stuff, and provides you with a clean interface.

cambraca
  • 27,014
  • 16
  • 68
  • 99
3

I think AJAX is just the name of something that happens

Ajax means "Making an HTTP request and processing the response using JavaScript without leaving the page".

and it's built into libraries like jQuery?

There are plenty of libraries which provide helper functions to make doing Ajax easier.

So, how do I figure out what ajaxSubmit() and other ajax-appended functions do?

ajaxSubmit is defined in the answer you are looking at. If you have trouble understanding what the function calls in the body of that answer do, then it is worth pointing out that it makes heavy use of jQuery which has its own documentation.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

In that tutorial ajaxSubmit is just the way he has named his function. You can see that in the line:

var ajaxSubmit = function(...

The real magic of the Ajax call is happening in the $.ajax() line.

See jQuery ajax docs here.

njr101
  • 9,499
  • 7
  • 39
  • 56
  • That makes sense to me, in hindsight. I still don't understand what the parameter is, though. I don't see where it ever achieves a value. – Wolfpack'08 Oct 14 '11 at 09:33
  • Oh. Actually, I read more deeper into the file, and it became apparent what was happening! Wow! Now I feel very silly. Thanks. :) – Wolfpack'08 Oct 14 '11 at 09:37
1

ajaxSubmit() is an anonymous function that is called when the onSubmit event is triggered. In this case, when the user clicks on the submit button in the example.

jQuery function that is actually doing the AJAX request is $.ajax()

I would suggest that you go through a couple of HTML and JavaScript tutorials to get a grasp on basic stuff before moving on to more complicated concepts. Libraries like jQuery are useful when you already know the underlying concepts, but they are not a silver bullet.

Christian P
  • 12,032
  • 6
  • 60
  • 71
  • Cool, thanks for the jQuery link. I'm not sure what anonymous functions are, so I'll have to read through some additional material. I'm looking at a definition that says they're 'function constants'. – Wolfpack'08 Oct 14 '11 at 09:35
  • @Wolfpack'08 I updated my answer and added another link for anonymous functions. – Christian P Oct 14 '11 at 10:01
  • Looking at your link, I also remember that anonymous functions were described in one of the chapters I've read (you can use ctrl+f to find it here. I really appreciate the help you've given me in solidifying this knowledge. – Wolfpack'08 Oct 14 '11 at 14:13
  • I wouldn't advice someone to not rely on libraries to do all of the work for them. Businesses can't work in that way. If you create your own version of the wheel, you become counter productive. If you're in school (CS maybe?), then you should understand this stuff. I don't see many many Android developers trying to understand what the kernel does for them. That would be very counter productive. Not everyone on SO is a computer science person. Although we would love it if everyone understood concepts better, you can't force people into your religion. Get the job done using the right tools. – pqsk May 08 '14 at 13:22
  • @pqsk you missed my point - of course everyone should use the jQuery and all other useful libraries; I didn't write that.I recommended to the OP that he should learn some basic JavaScript that every developer working on front end should now. Also, comparing learning the Linux kernel to JavaScript closures? – Christian P May 08 '14 at 14:50
  • @ChristianP I guess I did miss your point, but it just seemed by you saying "Don't rely on jQuery or other libraries to do all the work for you", that you were implying to the inner workings of ajax. jQuery is coded in such a way that a monkey can code in JavaScript. It makes things like ajax and DOM manipulation so easy, without knowing how to do it manually yourself and dealing with browsers, etc. I was not comparing the kernel to closures, I was comparing abstraction. Just like you would compare an API to using a car. I did not realize that you were referring to closures specifically. – pqsk May 08 '14 at 17:02
  • @pqsk the last sentence is probably ambiguous and that probably confused you. – Christian P May 09 '14 at 06:22