Results 1 to 2 of 2

Thread: Got encountered problem in ajax by stopped process but no error

  1. #1
    Join Date
    Sep 2010
    Posts
    188

    Got encountered problem in ajax by stopped process but no error

    Hi..

    I have ajax code for saving data to database
    here is my ajax code:

    Code:
    <script type="text/javascript">
    var ajaxTimeOut = null;
    var ajaxTimeOutOperator = null; 
    var responsePHP; // = "no_reply"
    var responsePHPOperator;
    var changeFocus; //= false;
    var transactionWasSaved;
    
    function remoteRequestObject() {
        var ajaxRequest = false;
        try {
            ajaxRequest = new XMLHttpRequest();
        }
        catch(err) {
            try{
                ajaxRequest = new ActiveXObject("MSxml2.XMLHTTP");
            }
            catch(err) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(err){
                    // --> change to DOM alert("Not Supported Browser") + err.description;
                    notify('Not Supported Browser.');
                    return false;
                }
            }
        }
        return ajaxRequest;
    } 
    
    //var ajaxRequest; // = remoteRequestObject();
    var ajaxRequest = remoteRequestObject();   
    var ajaxRequestOperator;
    </script>
    
    <script type="text/javascript">
    function lotIdCheck(element) {
        if (window.event.keyCode==13 || window.event.keyCode==10) {
            
            var txtElementID = element;
            if (txtElementID.value == "") { return false; }
           // alert(txtElementID.value);
         
                        if (ifMatch(txtElementID.value, document.getElementById('txtLotCode').value)) {
                           capture(element);
                        }
                        else {
                           
                           txtElementID.value = "";
                           txtElementID.focus();
                           notify("Lot ID mismatch.Scan again"); //box instead of this... 
                           
           
            }        
        }    
    }
    
    
    function timeOut(object) { 
    
      if (ajaxTimeOut != null) {
          window.clearTimeout(ajaxTimeOut);   
      }    
      //alert("this is the reponse " + responsePHP)
       if (changeFocus = false || responsePHP == "no_reply" || ajaxRequest.readyState != 4 && ajaxRequest.readyState != 0) {
          //alert('ajaxRequest not ready');
          ajaxRequest.onreadystatechange = function() {};   
          ajaxRequest.abort();
          document.getElementById(object).disabled = false;
          document.getElementById(object).value = "";
          changeInputType(document.getElementById(object),'password');
     
          document.getElementById(object).focus();
          document.getElementById(object).focus();
          
          var txt = document.getElementById(object);
          if (txt.attachEvent) {
              txt.attachEvent ("onkeypress", function () {lotIdCheck(txt)});
          }  
          //notify("Please Scan again.");  
          alert("Please Scan again.");
          
       }
       else {
          return false;
       }
    }
    
    function timeOutOperator() { 
    
    if (ajaxTimeOutOperator !== null) {
          window.clearTimeout(ajaxTimeOutOperator);   
      }    
    
    if (transactionWasSaved = false || responsePHPOperator == "no_reply" || ajaxRequestOperator.readyState != 4 && ajaxRequestOperator.readyState != 0) {
          //alert('ajaxRequest not ready');
          ajaxRequestOperator.onreadystatechange = function() {};   
          ajaxRequestOperator.abort();
          document.getElementById('txtLotCode').disabled = false;
          document.getElementById('txtLotCode').value = "";
          document.getElementById('txtLotCode').focus();
          document.getElementById('txtLotCode').focus();
          //notify("Please Scan again.");  
          alert("Please Scan again.");   
    }
       else {
          return false;
       }
    }
    
    
    function clearTiming() {
        changeFocus = true;
        if (ajaxTimeOut !== null) {
          window.clearTimeout(ajaxTimeOut);   
      }  
    }
    
    function clearTimingOperator() {
        transactionWasSaved = true;
        if (ajaxTimeOutOperator !== null) {
          window.clearTimeout(ajaxTimeOutOperator);   
      }  
    }
    
    function postSet() {
        if (window.event.keyCode==13 || window.event.keyCode==10) {
            document.getElementById('txtLotCode').disabled = true;
            
            verifyLotcode();
        }
    }
    
    //------------------------------------------------------------------------------------------------------------------
    
    function verifyLotcode() {
    responsePHPOperator = "no_reply";
    transactionWasSaved = false;
    ajaxRequestOperator = remoteRequestObject();
    ajaxRequestOperator.onreadystatechange = function () {
    if (ajaxRequestOperator.readyState==4 && ajaxRequestOperator.status==200) {
         //var result = ajaxRequestOperator.responseText;
         
         responsePHPOperator = ajaxRequestOperator.responseText; 
         
       //  alert(responsePHPOperator);
         if (responsePHPOperator == "failed") {
            document.getElementById('txtLotCode').disabled = false;
            document.getElementById('txtLotCode').value = "";
            document.getElementById('txtLotCode').focus();
           // notify("Please scan again.");
           alert("Please scan again.");
         }
         
         if (responsePHPOperator == "0") {
             
         //->> change to DOM    alert("Unauthorized operator");
            // notify("Unauthorized operator.<br />Scan Again.");
            alert("Unauthorized operator.<br/>Scan Again.");
             if (document.getElementById('txtLotCode').disabled) {
                 document.getElementById('txtLotCode').disabled = false; 
             } 
             document.getElementById('txtLotCode').value = "";
             document.getElementById('txtLotCode').focus();
         }
         else { 
            // alert ('correct');
             save();                
           //  notify("Transaction has been saved.");
           //  reset();
         }    
       }
    } 
    
    var str = document.getElementById('txtLotCode').value;
    var url = "validate_lotcode.php?q="+str;
    ajaxRequestOperator.open("GET",url , true );           
    
    // force i.e. not to cache
    ajaxRequestOperator.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    //---------------------------
    ajaxRequestOperator.send(null);
    ajaxTimeOutOperator = window.setTimeout("timeOutOperator();", 100000000);              
    }
    
    function save() {
     // ajaxRequest = remoteRequestObject();              
        ajaxRequest.onreadystatechange = function () {
        if (ajaxRequest.readyState==4 && ajaxRequest.status==200) {
           var result = ajaxRequest.responseText;
           
           // alert (result);
              
               if (result == "failed") {
                 // alert (result);
                document.getElementById('txtLotCode').disabled = false;
                document.getElementById('txtLotCode').value = "";
                document.getElementById('txtLotCode').focus();
                //notify("Please scan again.");
               alert("Please scan again");
               }
               
               if (result == "saved|saved" || result == "saved|saved|saved") {
                  //alert(result);
                 alert("Transaction has been saved.");
                  //notify("Transaction has been saved.");
                //  reset();
               }   
               
           }     
        }      
     
                 var parameters = "txtLotCode=" + encodeURI(document.getElementById('txtLotCode').value); 
    
     var url = "update_dependency.php";  
     
    
    ajaxRequest.open("POST", url, true);
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequest.setRequestHeader("Content-length", parameters.length);
    ajaxRequest.setRequestHeader("Connection", "close");
    ajaxRequest.send(parameters);
    }
    </script>
    
    
    <script type="text/javascript">
    function reset() {
            // alert ('reset');
           //enable elements
           
           document.getElementById('txtLotCode').disabled = false;
           
           //reset
      
      document.getElementById('txtLotCode').value = "";  
    }
    </script>
    I got problem in function save, even it satisfied this code:

    Code:
    if (result == "saved|saved" || result == "saved|saved|saved") {
    but it did not post alert and also not go to reset function.


    I don't know why?

    Thank you

  2. #2
    Join Date
    Mar 2012
    Location
    Australia
    Posts
    48
    Oh that's quite a code for ajax, Thanks for posting yours . I dont really get the idea of the problem coz it seems your code is running okay but the output is not portraying the correct one. Better check again all the codes itself might have something to do with it.

Similar Threads

  1. Having problem php and ajax
    By xhtmlpress in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 14 Apr 2012, 07:37 AM
  2. Embedded flash stopped working in Firefox
    By codemonkey in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 20 Dec 2010, 11:42 AM
  3. Problem in php ajax post value.
    By youlichika in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 06 Dec 2010, 07:40 PM
  4. jquery and ajax problem
    By maximus8888 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 15 Apr 2010, 01:12 AM

Posting Permissions

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