1 Replies - 11297 Views - Last Post: 12 January 2013 - 12:51 AM Rate Topic: -----

#1 cyberphoenix   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-January 13

Ajax php login query via onlick

Posted 12 January 2013 - 12:10 AM


I am building a webpage and i found that most of my functions requires the whole webpage to reload. for example login the page will reload and display success or error. I found out that ajax can be used. the problem is that i don't know how.sI made this code and it does not work. I did it by onchange but not using onlick. this is my code fragment
<title>Untitled Document</title>
        function call_login(username, password)
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            var klient;
            function ajax(filurl) {
                 klient = new XMLHttpRequest();
                 klient.onreadystatechange = hanterare;
                 klient.open("GET", filurl);
            function hanterare() {
                document.getElementById("utdata").innerHTML= klient.responseText;

    <input type="text" name="usermame" id="username">
      <label for="password"></label>
      <input type="password" name="password" id="password">
      <input type="submit" name="call_login" id="call_login" value="Submit" onclick="call_login(document.getElementById('username'), document.getElementById('password')">
<label for="call_login"></label>

Hope somebody helps. Thanks!

This post has been edited by Dormilich: 12 January 2013 - 12:42 AM
Reason for edit:: fixed code tags

Is This A Good Question/Topic? 0
  • +

Replies To: Ajax php login query via onlick

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: Ajax php login query via onlick

Posted 12 January 2013 - 12:51 AM

there are several problems:
- the onclick handler is missing a )
- the username and password parameters are passed form elements, not strings (i.e. they are converted to the string [object HTMLInputElement], which will definitely not log you in)
- ajax() will not work in older IEs
- the "utdata" element does not exist
- the button click will load a new page. then why bother using AJAX?
- the <form>ís required action attribute is missing
- the upper part oft the HTML header (DTD, <head>, <title>) is missing (might be a copy error)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1