Solved

AJAX Error Code 0x80040111

Posted on 2007-11-23
8
1,016 Views
Last Modified: 2013-12-07
I am having a problem with Firefox whenever a form is submitted. When a form is submitted, if the validation comes out to true, then another function is called which inserts the fields in my database before the action of the form is performed. The action is to another URL, which is the merchant account. In internet explorer, all the information is correctly inserted into my database. In FF though, nothing is inserted, and whenever I check the error console, I see this error:

Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: https://www.jcbodyworks.net/ajax.js :: anonymous :: line 1485"  data: no]
Source File: https://www.jcbodyworks.net/ajax.js
Line: 1485

The exact function is this:

function ccsubmit()
{
      var obj1 = document.getElementById("cctype");
      var obj2 = document.getElementById("bname");
      var obj3 = document.getElementById("cardnumber");
      var obj4 = document.getElementById("expmonth");
      var obj5 = document.getElementById("expyear");
      var obj6 = document.getElementById("baddr1");
      var obj7 = document.getElementById("bcity");
      var obj8 = document.getElementById("bstate");
      var obj9 = document.getElementById("bzip");
      var obj10 = document.getElementById("cvm");
      
      var cctype = obj1.options[obj1.selectedIndex].value;
      var bname = obj2.value;
      var cardnumber = obj3.value;
      var expmonth = obj4.options[obj4.selectedIndex].value;
      var expyear = obj5.options[obj5.selectedIndex].value;
      var baddr1 = obj6.value;
      var bcity = obj7.value;
      var bstate = obj8.options[obj8.selectedIndex].value;
      var bzip = obj9.value;
      var cvm = obj10.value;
      
      var dataSource = "ajax.php?insertcc=yes";
      
      document.getElementById("errormessage").innerHTML = "...Pleast Wait...";


      
            if (window.XMLHttpRequest) {
            XMLHttpRequestObject =  new XMLHttpRequest();
            } else if (window.ActiveXObject) {
            XMLHttpRequestObject = new
            ActiveXObject("Microsoft.XMLHttp");
            }
            
            if (XMLHttpRequestObject) {
                  XMLHttpRequestObject.open("POST", dataSource);
                  XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');


            XMLHttpRequestObject.onreadystatechange = function()
            {
                  if (XMLHttpRequestObject.readyState == 4 &&
                        XMLHttpRequestObject.status == 200) {
                        
                        eval(XMLHttpRequestObject.responseText);
                        
                        delete XMLHttpRequestObject;
                        //XMLHttpRequestObject = null;
                        }
            }
            XMLHttpRequestObject.send("cctype=" + cctype +"&bname=" + bname +"&cardnumber=" + cardnumber +"&expmonth=" + expmonth +"&expyear=" + expyear +"&baddr1=" + baddr1 +"&bcity=" + bcity +"&bstate=" + bstate +"&bzip=" + bzip +"&cvm=" + cvm);
      }
}

the line with the error is (according to the error console):

XMLHttpRequestObject.status == 200) {

I googled the issue, and it seems I am not alone, but I am not sure how to implement a solution to this problem? It puzzles me how this error would randomly be thrown like this? Could it have something to do with the function being called at the same time as the form submission? The form looks like this:

<form name="payment_form" action="https://www.linkpointcentral.com/lpc/servlet/lppay" method="POST" onSubmit="return validate_form();">
.......
</form>

the function for that is:

function validate_form()
{
    valid = true;

    if (cctype == "")
    {
        document.getElementById("errormessage").innerHTML = "Please select a credit card type.";
            valid = false;
      
    }
      
      else if (
      ((cctype == "V") && ((cardnumber.substring(0,1) != 4) || !((cardnumber.length == 13) || (cardnumber.length == 16)))) ||
   
      ((cctype == "M") && ((cardnumber.substring(0,2) < 51)  || (cardnumber.substring(0,2) > 56) || (cardnumber.length != 16))) ||
   
    ((cctype == "A") && (!((cardnumber.substring(0,2) == 34)  || (cardnumber.substring(0,2) == 37)) || (cardnumber.length != 15))) ||
      
      ((cctype == "D") && ((cardnumber.substring(0,4) == 6011) || (cardnumber.length != 16)))
      )
    {
      document.getElementById("errormessage").innerHTML = "Please enter a valid credit card number.";      
      valid = false;
      
      }
      
      else if ( bname == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please type in your full name.";
            valid = false;
            
    }
      
      else if ( expmonth == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter your expiration month.";
            valid = false;
            
    }
      
      else if ( expyear == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter your expiration year.";
            valid = false;
            
    }
      
      else if ( baddr1 == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the address associated with your credit card.";
            valid = false;
            
    }
      
      else if ( bcity == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the city associated with your credit card.";
            valid = false;
            
    }
      
      else if ( bstate == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the state associated with your credit card.";
            valid = false;
            
    }
      
      else if ( bzip == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the zip code associated with your credit card.";
            valid = false;
            
    }
      
      else if ( cvm == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the card code associated with your credit card.";
            valid = false;
    }
      
      else if ( valid == true )
      {
            
    ccsubmit();
            
      }

      return valid;
      

}

Any help or fresh ideas on solving this issue would greatly be appreciated!
0
Comment
Question by:jcbodyworks
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20338350
Try adding



add it after:
            if (XMLHttpRequestObject) {
                  XMLHttpRequestObject.open("POST", dataSource);
                  XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                  XMLHttpRequestObject.send(null);
0
 
LVL 4

Expert Comment

by:simonkin
ID: 20338364
Hi,

Try a function re-write with catch statements...

Like this...
function ccsubmit()
{
      var obj1 = document.getElementById("cctype");
      var obj2 = document.getElementById("bname");
      var obj3 = document.getElementById("cardnumber");
      var obj4 = document.getElementById("expmonth");
      var obj5 = document.getElementById("expyear");
      var obj6 = document.getElementById("baddr1");
      var obj7 = document.getElementById("bcity");
      var obj8 = document.getElementById("bstate");
      var obj9 = document.getElementById("bzip");
      var obj10 = document.getElementById("cvm");
      
      var cctype = obj1.options[obj1.selectedIndex].value;
      var bname = obj2.value;
      var cardnumber = obj3.value;
      var expmonth = obj4.options[obj4.selectedIndex].value;
      var expyear = obj5.options[obj5.selectedIndex].value;
      var baddr1 = obj6.value;
      var bcity = obj7.value;
      var bstate = obj8.options[obj8.selectedIndex].value;
      var bzip = obj9.value;
      var cvm = obj10.value;
	  
	  document.getElementById("errormessage").innerHTML = "...Pleast Wait...";
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
			// Output from the AJAX request below this...
			
			var ajaxDisplay = document.getElementById('errormessage');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			
			// ^ Output from the AJAX request above this...
		}
	}
	
	var dynamic = "&dynamic=" + Math.floor(Math.random()*99999999999999999); // So we can reuse the function if needed...
	var queryString = "&cctype=" + cctype + "&bname=" + bname + "&cardnumber=" + cardnumber + "&expmonth=" + expmonth + "&expyear=" + expyear + "&baddr1=" + baddr1 + "&bcity=" + bcity + "&bstate=" + bstate + "&bzip=" + bzip + "&cvm=" + cvm;
	ajaxRequest.open("GET", "ajax.php?insertcc=yes" + queryString + dynamic, true);
	ajaxRequest.send(null); 
}

Open in new window

0
 
LVL 17

Expert Comment

by:gops1
ID: 20338398
Mozilla browser suggest to use "" instead of null so you can try with:

XMLHttpRequestObject.send("");
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 29

Expert Comment

by:Badotz
ID: 20339020
You are using the synchronous method of the XMLHTTP object. For asynchronous calls, try:

XMLHttpRequestObject.open("POST", dataSource, true);
0
 

Author Comment

by:jcbodyworks
ID: 20339967
none of these solutions have worked.
0
 

Author Comment

by:jcbodyworks
ID: 20340095
guys, I solved the problem on my own. May you can explain why I would have to do this long process....but here is what I did:

First, I changed the event of the form submission from an onSubmit to an onClick on the submit image, like this:

<a href="#" onClick="validate_form();return false;"><img src="submittwo.jpg"></a>

the validate form looks like this:

function validate_form()
{
      var valid;
      
      var obj1 = document.getElementById("cctype");
      var obj2 = document.getElementById("bname");
      var obj3 = document.getElementById("cardnumber");
      var obj4 = document.getElementById("expmonth");
      var obj5 = document.getElementById("expyear");
      var obj6 = document.getElementById("baddr1");
      var obj7 = document.getElementById("bcity");
      var obj8 = document.getElementById("bstate");
      var obj9 = document.getElementById("bzip");
      var obj10 = document.getElementById("cvm");
      
      var cctype = obj1.options[obj1.selectedIndex].value;
      var bname = obj2.value;
      var cardnumber = obj3.value;
      var expmonth = obj4.options[obj4.selectedIndex].value;
      var expyear = obj5.options[obj5.selectedIndex].value;
      var baddr1 = obj6.value;
      var bcity = obj7.value;
      var bstate = obj8.options[obj8.selectedIndex].value;
      var bzip = obj9.value;
      var cvm = obj10.value;

    if (cctype == "")
    {
        document.getElementById("errormessage").innerHTML = "Please select a credit card type.";
            var valid=false;
    }
      
      else if (
      ((cctype == "V") && ((cardnumber.substring(0,1) != 4) || !((cardnumber.length == 13) || (cardnumber.length == 16)))) ||
   
      ((cctype == "M") && ((cardnumber.substring(0,2) < 51)  || (cardnumber.substring(0,2) > 56) || (cardnumber.length != 16))) ||
   
    ((cctype == "A") && (!((cardnumber.substring(0,2) == 34)  || (cardnumber.substring(0,2) == 37)) || (cardnumber.length != 15))) ||
      
      ((cctype == "D") && ((cardnumber.substring(0,4) == 6011) || (cardnumber.length != 16)))
      )
    {
      document.getElementById("errormessage").innerHTML = "Please enter a valid credit card number.";      
      var valid=false;
      }
      
      else if ( bname == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please type in your full name.";
            var valid=false;
    }
      
      else if ( expmonth == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter your expiration month.";
            var valid=false;
    }
      
      else if ( expyear == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter your expiration year.";
            var valid=false;
    }
      
      else if ( baddr1 == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the address associated with your credit card.";
            var valid=false;
    }
      
      else if ( bcity == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the city associated with your credit card.";
            var valid=false;
    }
      
      else if ( bstate == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the state associated with your credit card.";
            var valid=false;
    }
      
      else if ( bzip == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the zip code associated with your credit card.";
            var valid=false;
    }
      
      else if ( cvm == "" )
    {
        document.getElementById("errormessage").innerHTML = "Please enter the card code associated with your credit card.";
            var valid=false;
    }
      
      else if (valid != false )
      {
            
    ccsubmit('ajax.php?insertcc=yes');
            
      }
      

}

if the validate_form function comes out alright, it then calls another function, which submits that data to my database. This looks like this:

function ccsubmit(dataSource)
{
      var obj1 = document.getElementById("cctype");
      var obj2 = document.getElementById("bname");
      var obj3 = document.getElementById("cardnumber");
      var obj4 = document.getElementById("expmonth");
      var obj5 = document.getElementById("expyear");
      var obj6 = document.getElementById("baddr1");
      var obj7 = document.getElementById("bcity");
      var obj8 = document.getElementById("bstate");
      var obj9 = document.getElementById("bzip");
      var obj10 = document.getElementById("cvm");
      
      var cctype = obj1.options[obj1.selectedIndex].value;
      var bname = obj2.value;
      var cardnumber = obj3.value;
      var expmonth = obj4.options[obj4.selectedIndex].value;
      var expyear = obj5.options[obj5.selectedIndex].value;
      var baddr1 = obj6.value;
      var bcity = obj7.value;
      var bstate = obj8.options[obj8.selectedIndex].value;
      var bzip = obj9.value;
      var cvm = obj10.value;
      
      document.getElementById("errormessage").innerHTML = "...Pleast Wait...";

            if (window.XMLHttpRequest) {
            XMLHttpRequestObject =  new XMLHttpRequest();
            } else if (window.ActiveXObject) {
            XMLHttpRequestObject = new
            ActiveXObject("Microsoft.XMLHttp");
            }
            
            if (XMLHttpRequestObject) {
                  XMLHttpRequestObject.open("POST", dataSource);
                  XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                  

            XMLHttpRequestObject.onreadystatechange = function()
            {
                  if (XMLHttpRequestObject.readyState == 4 &&
                        XMLHttpRequestObject.status == 200) {
                        
                        eval(XMLHttpRequestObject.responseText);
                        
                        delete XMLHttpRequestObject;
                        XMLHttpRequestObject = null;
                        }
            }
            XMLHttpRequestObject.send("cctype=" + cctype +"&bname=" + bname +"&cardnumber=" + cardnumber +"&expmonth=" + expmonth +"&expyear=" + expyear +"&baddr1=" + baddr1 +"&bcity=" + bcity +"&bstate=" + bstate +"&bzip=" + bzip +"&cvm=" + cvm);
      }
}

Then, in the PHP code, after all the data is inserted, I send out an ech JavaScript code which will submit the form over, like this:

function insertcc()
{
$username=$_SESSION['username'];

$cctype=$_POST['cctype'];
$bname=$_POST['bname'];
$cardnumber=$_POST['cardnumber'];
$expmonth=$_POST['expmonth'];

$expyear=$_POST['expyear'];
$ccaddres=$_POST['baddr1'];
$cccity=$_POST['bcity'];
$ccstate=$_POST['bstate'];
$cczipcode=$_POST['bzip'];
$cvm=$_POST['cvm'];

$query="UPDATE clientele SET cctype='$cctype', ccfullname='$bname', ccnumber='$cardnumber', ccmonth='$expmonth', ccyear='$expyear', ccaddress='$ccaddres', cccity='$cccity', ccstate='$ccstate', ccstate='$ccstate', cczipcode='$cczipcode', cccode='$cvm' WHERE username='$username'";
mysql_query($query) or die(mysql_error());

echo 'window.document.payment_form.submit();';

}

I dont understand why, but maybe it has something to do with the the AJAX object needing its own time to perform its call before the form is submitted? Not sure, but I figured the best way was to let the PHP code send out the final call when it was done doing its task. This definitely works.
0
 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
ID: 20340178
You invoked the XMLHTTP call SYNCHRONOUSLY, not ASYNCHRONOUSLY, so your callback routine responded whenever it could.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 20413794
No worries - glad to hlep.

Since my solution was posted twice, do I get double points? ;-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question