/    Sign up×
Community /Pin to ProfileBookmark

Preparing post headers in JavaScript

Alright, I’m working on a login form. I want it to have AJAX capability, while making it compatible with those with JavaScript turned off, so I have something like this:

[code]
<form action=”” method=”POST” onsubmit=”sendAjax(); return false; “>
Username: <input type=”text” name=”username” />
Password: <input type=”password” name=”password” />
<input type=”submit” name=”submit” value=” Login ” />
</form>
[/code]

Everything alright so far? So, the idea is, the form submits to itself, but, if the user has JavaScript enabled, the form will, instead, be sent by AJAX to the server.

My problem is, how do I build up the post headers in JavaScript to send to the server? Or, do they do that automatically, since it’s an onsubmit trigger?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 22.2005 — Yes, the value pairs are picked up server-side.

The only reason to use onsubmit is to validate the form client-side, to save a possible extra trip to the server.
Copy linkTweet thisAlerts:
@provauthorJun 22.2005 — The only reason to use onsubmit is to validate the form client-side, to save a possible extra trip to the server.[/QUOTE]

Not if you're using AJAX... that's the whole reason I'm asking this question. ?
Copy linkTweet thisAlerts:
@FangJun 22.2005 — So what is JavaScript doing that isn't duplicated on the server?
Copy linkTweet thisAlerts:
@felgallJun 22.2005 — The only thing Javascript does that isn't duplicated on the server is to report any errors in the form before it is submitted.
×

Success!

Help @prov spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...