Solved

AJAX Error Code 0x80040111

Posted on 2007-11-23
8
1,007 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
Comment Utility
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
Comment Utility
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
Comment Utility
Mozilla browser suggest to use "" instead of null so you can try with:

XMLHttpRequestObject.send("");
0
 
LVL 29

Expert Comment

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

XMLHttpRequestObject.open("POST", dataSource, true);
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jcbodyworks
Comment Utility
none of these solutions have worked.
0
 

Author Comment

by:jcbodyworks
Comment Utility
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
Comment Utility
You invoked the XMLHTTP call SYNCHRONOUSLY, not ASYNCHRONOUSLY, so your callback routine responded whenever it could.
0
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
No worries - glad to hlep.

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now