0

Hi i would like to create a login page in html 5, but in order to login i need to send the username and password to a web service, the web service is already created and it will return a value 0 if flase and any other number if true. I can only use javascript and json. Can anyone help me out to understand json as i know almost nothing about it. How would i send the username and password using json and javascript?

1
  • 1
    What have you tried? Is there a specific thing that's hanging you up? You get better answers when you have specific questions and code showing what you've done so far.
    – Alex Wayne
    Dec 21, 2012 at 6:46

1 Answer 1

2
var form;

form.onsubmit = function (e) {
  // stop the regular form submission
  e.preventDefault();

  // collect the form data while iterating over the inputs
  var data = {};
  for (var i = 0, ii = form.length; i < ii; ++i) {
    var input = form[i];
    if (input.name) {
      data[input.name] = input.value;
    }
  }

  // construct an HTTP request
  var xhr = new XMLHttpRequest();
  xhr.open(form.method, form.action, true);
  xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

  // send the collected data as JSON
  xhr.send(JSON.stringify(data));

  xhr.onloadend = function () {
    // done
  };
};
5
  • I am new to html 5 as my company just asked me to create this with this requirements. I personally only know c# and vb. I created the login page in html and that is as far as i have done Dec 21, 2012 at 6:50
  • may I recommand yu a tutorial in HTML 5 ??? if yu have a basic knowledge of HTML, then it will take only an hour for yu to understand it... go to w3schools.com/html/html5_intro.asp
    – I.C.A.
    Dec 21, 2012 at 6:52
  • 1
    Yes that would be great. Thanks alot i will try out this coding now Dec 21, 2012 at 6:57
  • must i just copy and paste it into my javascript page and it will run? sorry lol am new to javascript Dec 21, 2012 at 7:04
  • and where do add the url of the web service? Dec 21, 2012 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.