Results 1 to 2 of 2

Thread: AJAX: XMLHttpRequest.open() not working

Hybrid View

  1. #1
    Join Date
    Nov 2010

    AJAX: XMLHttpRequest.open() not working

    I am facing a problem while applying ajax in my login script.

    My login form is :

    <form action="" id="contactform" onsubmit="return loadXMLDoc();">
    <div id= "login">  
    <font face="Georgia" size="-1">
     <input type='button' id='button' name='login_user' value='Login' onclick='loadXMLDoc();'/>
    <span id="txtHint"></span>
    Ajax code is:

    <script type="text/javascript">
    var ajaxRequest; 
    function ajaxFunction(){
       ajaxRequest = new XMLHttpRequest();
     }catch (e){
       // Internet Explorer Browsers
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
       }catch (e) {
             ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
          }catch (e){
             alert("Your browser broke!");
             return false;
    function processRequest() {
       if (req.readyState == 4) {
          var ajaxDisplay = document.getElementById('txtHint');
          ajaxDisplay.value = ajaxRequest.responseText;
    function loadXMLDoc() {
       // Here processRequest() is the callback function.
         var url = 'login.php';
       if (!target) var target = document.getElementById("textfield").value;
       if (!target1) var target1 = document.getElementById("textfield2").value;
       var mainurl = url + "?uname=" + target;
       mainurl = mainurl + "&pass=" + target1;   
       mainurl = mainurl + "&login=" + '1';
       ajaxRequest.open("POST", mainurl, true);
       ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       ajaxRequest.onreadystatechange = processRequest;

    Now, whenever I click login button, nothing happens. I have checked url and it shows login.php?uname=&pass=&login=1
    The script is not able to call login.php

    login.php is [kept simple for testing]

    PHP Code:
    // makes sure they filled it in 
    if((!$_GET['uname']) || ($_GET['uname']=='') || (!$_GET['pass']) || ($_GET['pass']=='')) { 
    $response="Please fill"
    <script type="text/javascript"> 
    alert('please fill'); 
    echo $response
     die(); } 

    After clicking login button....I am getting any of the messages...

    please help...

  2. #2
    Join Date
    Dec 2002
    St. Louis, MO, USA
    What error messages are being displayed? If it's not working, there's most likely an error message.

    Either the yellow exclamation point icon in the lower-left of IE, or in FF's Error Console.
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles