www.webdeveloper.com
Results 1 to 2 of 2

Thread: AJAX: XMLHttpRequest.open() not working

  1. #1
    Join Date
    Nov 2010
    Posts
    1

    AJAX: XMLHttpRequest.open() not working

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

    My login form is :


    Code:
    <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();'/>
    
    </form>
    <span id="txtHint"></span>
    Ajax code is:

    Code:
    <script type="text/javascript">
    
    var ajaxRequest; 
    function ajaxFunction(){
     try{
       
       ajaxRequest = new XMLHttpRequest();
     }catch (e){
       // Internet Explorer Browsers
       try{
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
       }catch (e) {
          try{
             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() {
    
       ajaxFunction();
       // 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';
       alert(mainurl);
       ajaxRequest.open("POST", mainurl, true);
       ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       ajaxRequest.onreadystatechange = processRequest;
       ajaxRequest.send(mainurl);
    
    }
    
    </script>


    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:
    <?php 
    // 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'); 
    </script> 
    <?php 
    echo $response
     die(); } 

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

    please help...

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    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.

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