Jump to content

xmlhttp doing nonsense in ie


r-it

Recommended Posts

i have this code:

<script>
function dologin(f)
{
var login = f.txLogin.value;
var pass = f.txPass.value;
var val = "top";

var obj = document.getElementById(val);
var url = "check.php?logn=" + login + "&pass=" + pass;
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function()
{
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
	{
		obj.innerHTML = xmlhttp.responseText;

	}

}

xmlhttp.send(null);
}
</script>

 

which basically handles my login form

 

the thing is that it works fine in firefox, but internet explorer 6 is giving me a headache as it is just reloading the page instead of showing a message, i have not made a function for creating the mttprequests, they are rather declared at the top of my js script and are used (globally) throughout the script:

//create a boolean variable to check for a valid IE instance
var xmlhttp = false;

//check if user's using IE
try
{
//check if jvascript version is rgeater than 5.
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
}
catch (e)
{
//if nt, then use older active x object
try
{
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
	//else, user's not using IE
	xmlhttp = false;
}
}

//if user's using a non-ie browser, create a javascript instance of the obj
if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
xmlhttp = new XMLHttpRequest();
}

 

the reloading happens after i get the responseText back, it completely reloads the page, and when i put an alert after the responsetext, then i can see the message in the page behind the alertbox, but as soon as i click ok, it reloads the page again, please help

Link to comment
Share on other sites

I would recommend that you put your xmlhttp object into a separate function so that it is reusable. Here is one of the best that I have been able to find.

 

//ober's xmlhttp function
function createRequestObject() {
    if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        var xmlhttp = new XMLHttpRequest();
        //for actual xml responses
	//if (xmlhttp.overrideMimeType)
		//xmlhttp.overrideMimeType('text/xml');
    }
else if (window.ActiveXObject) { // IE
        try {
            var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!xmlhttp) {
        alert('Giving up  Cannot create an XMLHTTP instance');
        return false;
    }
return xmlhttp;
}

var http = createRequestObject();

function dologin(f) {
var login = f.txLogin.value;
var pass = f.txPass.value;
var val = "top";

var obj = document.getElementById(val);
var url = "check.php?logn=" + login + "&pass=" + pass;
http.open("GET", url, true);
        http.send(null);//this needs to come before your state change function
http.onreadystatechange = function() {
	if(http.readyState == 4 && http.status == 200) {
		obj.innerHTML = http.responseText;

	}

}
}

 

 

Link to comment
Share on other sites

what is the message that is returned?  ie can be very finicky about what you innerHTML into something.  Complex html, js, or forms can cause you problems.  Or if you try to inject a block level item into an inline item, like inject a div into a span. (block level item not allowed in inline item)

 

If the code injected is not well formed it's even more finicky.

Link to comment
Share on other sites

the error is an unknown runtime error, which only appears when i have the form tag there, but when i ommit it, then it appears, and i have tested my code on the w3c validator and it passed, i dont know what else could be wrong, here is my form code below:

 

<?php
$form = "
<table width=\"540\" align=\"center\">
<tr><td colspan=\"3\"><h2>SUBSCRIPTION</h2></td></tr>
<tr><td colspan=\"3\">Subscribe to the QDOS Legal Service and receive full access to QDOS Legal Online and the Employment Law advice line. For full product details <a href=\"//\">CLICK HERE</a></td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\" align=\"justify\">To subscribe, please complete the registration process below. On receipt of the completed form, and once payment is confirmed, your profile (your unique login and password) will be enabled, allowing you immediate access to the QDOS Legal Online and/or Employment Law Advice Line.<br />Alternatively, please <a href=\"//\">Contact Us</a><br /><br /></td></tr>
<tr><td colspan=\"3\"><b>REGISTRANT DETAILS</b></td></tr>
<tr><td width=\"48%\">Name of company:</td><td width=\"2%\"> </td><td width=\"48%\">Tel:</td></tr>

<tr><td><input name=\"txCName\" type=\"text\" size=\"40\" /></td><td> </td><td><input type=\"text\" name=\"txTel\" size=\"40\" /></td></tr>
<tr><td>Name of contact person:</td><td> </td><td>Fax:</td></tr>
<tr><td><input name=\"txConPerson\" type=\"text\" size=\"40\" /></td><td> </td><td><input type=\"text\" name=\"txFax\" size=\"40\" /></td></tr>
<tr><td>Designation:</td><td> </td><td>Email:</td></tr>
<tr><td><input type=\"text\" name=\"txDesignation\" size=\"40\" /></td><td> </td><td><input type=\"text\" name=\"txMail\" size=\"40\" /></td></tr>
<tr><td>Address of company:</td><td> </td><td> </td></tr>
<tr><td><textarea name=\"txaAddress\" cols=\"30\" rows=\"3\"></textarea></td><td> </td><td> </td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\"><b>BUSINESS PROFILE</b></td></tr>
<tr><td>Main business activity:</td><td> </td><td>Other activities:</td></tr>
<tr><td><textarea name=\"txaMainAct\" cols=\"30\" rows=\"3\"></textarea></td><td> </td><td><textarea name=\"txaOtherAct\" cols=\"30\" rows=\"3\"></textarea></td></tr>
<tr><td>Number of employees<br />(include full and part-time staff):</td><td> </td><td><br />Annual turnover:</td></tr>
<tr><td><input name=\"txNumEmployees\" type=\"text\" size=\"40\" /></td><td> </td><td><input type=\"text\" name=\"txTurnover\" size=\"40\" /></td></tr>
<tr><td colspan=\"3\">Names and details of any associated businesses:</td></tr>
<tr><td colspan=\"3\"><textarea name=\"txaAssocBiz\" cols=\"65\" rows=\"4\"></textarea></td></tr>

<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\">Would you like us to contact you with regards to conducting a comprehensive employment law compliance audit in your company?</td></tr>
<tr><td colspan=\"3\"><input type=\"radio\" name=\"rdContact\" />Yes  <input type=\"radio\" name=\"rdContact\" />No</td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\"><h2>Subscription package</h2></td></tr>
<tr><td colspan=\"3\">Product/Service required:</td></tr>
<tr><td><input type=\"checkbox\" name=\"ckLegalOnline\" />QDOS Legal Online</td><td> </td><td><input type=\"checkbox\" name=\"ckLegalAdvice\" />QDOS Legal Advice Line</td></tr>
<tr><td><input type=\"checkbox\" name=\"ckBoth\" />QDOS Legal Online and Advice Line</td><td> </td><td><input type=\"checkbox\" name=\"ckOther\" />Other</td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr>
  <td colspan=\"3\">Please select the package which best suits you and your organisation.</td>
</tr>
<tr>
  <td colspan=\"3\">
  <table width=\"100%\">
  <tr>
  <td width=\"32%\"><i><br />QDOS Online only</i></td><td width=\"2%\"> </td><td width=\"32%\"><i>QDOS Legal<br />Advice Line</i></td><td width=\"2%\"> </td><td width=\"32%\"><i>QDOS Online & <br />Legal Advice Line</i></td></tr>
  <tr><td><input type=\"radio\" name=\"rdPackage\" /> 
1 user (R55)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 
1 user (R65)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 
1 user (R105)</td></tr>
  <tr><td><input type=\"radio\" name=\"rdPackage\" /> 2-5 users (R85)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 2-5 users (R95)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 2-5 users (R185)</td></tr>
  <tr><td><input type=\"radio\" name=\"rdPackage\" /> 6-10 users (R205)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 6-10 users (R250)</td><td> </td><td><input type=\"radio\" name=\"rdPackage\" /> 6-10 users (R290)</td></tr></table>
  
  </td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\"><b>PAYMENT METHOD</b><br /></td></tr>
<tr><td colspan=\"3\">Subscriptions to QDOS Legal Online and/or QDOS Legal Advice Line can be done in 3 ways. Select one of the payment options and an email will be sent to you containg all the detail you need to complete the chosen process.<br /></td></tr>

<tr><td colspan=\"3\"><input type=\"radio\" name=\"rdPay\" />Debit Order</td></tr>
<tr><td colspan=\"3\">By choosing Debit Order, an email will be sent to you containing a debit order authorisation form. Please complete the debit order authorisation form and fax to us on ...........</td></tr>
<tr><td colspan=\"3\"><input type=\"radio\" name=\"rdPay\" />Direct Deposit</td></tr>
<tr><td colspan=\"3\">By choosing Direct Deposit, an email will be sent to you containing our banking details. Please deposit the subscription amount and fax the deposit slip to us on ...........</td></tr>
<tr><td colspan=\"3\"><input type=\"radio\" name=\"rdPay\" />Cheque</td></tr>
<tr><td colspan=\"3\">By choosing Cheque, you are indicating that you will post a cheque to us at:<br />Subscriptions, QDOS Legal (Pty) Ltd., PO Box 1260, Cape Town, 8000. An email containing all the information you will need will be sent to you.</td></tr>
<tr><td colspan=\"3\"> </td></tr>
<tr><td colspan=\"3\"><input type=\"checkbox\" name=\"ckAgreement\" />Please check here to signal your agreement to our <a href=\"//\">terms and conditions</a></td></tr>
<tr><td colspan=\"3\">Preferred username:</td></tr>
<tr><td colspan=\"3\"><input name=\"txUsername\" type=\"text\" size=\"40\" /></td></tr>
<tr><td colspan=\"3\">Password:</td></tr>
<tr><td colspan=\"3\"><input name=\"txPass1\" type=\"password\" size=\"40\" /></td></tr>
<tr><td colspan=\"3\">Re-enter password:</td></tr>
<tr><td colspan=\"3\"><input name=\"txPass2\" type=\"password\" size=\"40\" /></td></tr>
<tr><td colspan=\"3\"><img src=\"./captcha.php\" alt=\"Security code\" /> (Please enter into the textbox below)</td></tr>
<tr><td colspan=\"3\"><input name=\"txCaptcha\" type=\"text\" size=\"40\" /></td></tr>
<tr><td colspan=\"3\"><input type=\"button\" value=\"Submit\" name=\"submit\" /></form></td></tr>
</table>";
?>

 

i use this variable to store the form values then i call it with a function, and i'm sure it's well formed.

Link to comment
Share on other sites

ie definitely does not like form tags innerHTML'ed.  Other posts in this forum show that it is a known problem.  I don't know if you can get away with putting the from tag outside the area to be innerHTML'ed:

<form>
<div id="fields_injected_here"></div>
</form>

that may or may not work.  innerHTML'ing form tags and form fields in ie is problematic and I don't know if anybody has solved it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.