Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-24-2012, 08:57 AM   PM User | #1
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
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
newphpcoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:47 AM.


Advertisement
Log in to turn off these ads.