I’m building a page with multiple forms. But they were all sent with 1 submit button.
It is similar to create project forms in kickstarter.com (http://www.kickstarter.com/start).
The code used in kickstarter is as follow:
$("#submit_for_review a").live("click", function (a) {
a.preventDefault();
var c = $(this),
d = $("#saving-layer");
d.show();
$.ajax({
url: c.attr("href"),
type: "get",
dataType: "json",
success: function (a) {
a.ok ? j(c, function () {
$("body").addClass("confirm_preview");
b("Preview", "Pre-Submit");
return !0
}) : ($.each(a, function (a, b) {
if (b) {
var c = $("#" + a.replace(/_/g, "-")).html(b);
window.FB && window.FB.XFBML && setTimeout(function () {
FB.XFBML.parse(c[0])
}, v)
}
}), e() && h($(".flash-error:first").closest(".panel").index()))
},
complete: function () {
d.hide()
}
})
});
Now my question is, how does this button send data via ajax ?
I can see there are parameters for url, type, dataType, success, complete, but how come there is no parameter data being sent and yet the server was able to accept all the data from all forms.
Could the data be passed through cookie or session ?
Appreciate any help on this.
The jQuery website has a good tutorial, with a section titled ‘Rate Me: Using AJAX’ (albeit it is XML not JSON). As a refresher it may be an idea to follow through the entire tutorial.
A key point is to remember that $ creates a new jQuery object.
For a refresher on AJAX with a process overview try the W3Schools page.