Hi I keep getting this error in firebug on this script "no element found" even after adding "header('Content-Type: text/plain');". Can anyone help? thanks.
categories.php
<?php
if(isset($_GET['1'])) {
header('Content-Type: text/plain');
echo <<<HERE_DOC
<option value="1.1">Antiquities ></option>
<option value="1.2">Architectural & Garden ></option>
<option value="1.3">Asian Antiques ></option>
<option value="1.4">Books & Manuscripts ></option>
<option value="1.5">Decorative Arts ></option>
<option value="1.6">Ethnographic ></option>
<option value="1.7">Furniture ></option>
<option value="1.8">Home & Hearth ></option>
<option value="1.9">Linens & Textiles (Pre-1930) ></option>
<option value="1.10">Maps, Atlases & Globes ></option>
<option value="1.11">Maritime ></option>
<option value="1.12">Mercantile, Trades & Factories ></option>
<option value="1.13">Musical Instruments (Pre-1930) ></option>
<option value="1.14">Periods &开发者_Python百科amp; Styles ></option>
<option value="1.15">Primitives;</option>
<option value="1.16">Restoration & Care ></option>
<option value="1.17">Rugs & Carpets ></option>
<option value="1.18">Science & Medicine (Pre-1930) ></option>
<option value="1.19">Sewing (Pre-1930) ></option>
<option value="1.20">Silver ></option>
<option value="1.21">Reproduction Antiques</option>
<option value="1.22">Other</option>
HERE_DOC;
}
if(isset($_GET['2'])) {
header('Content-Type: text/plain');
echo <<<HERE_DOC
<option value="60435">Direct from the Artist ></option>
<option value="158658">Art from Dealers & Resellers ></option>
<option value="52524">Wholesale Lots ></option>
HERE_DOC;
}
if(isset($_GET['3'])) {
header('Content-Type: text/plain');
echo <<<HERE_DOC
<option value="60435">Direct from the Artist ></option>
<option value="158658">Art from Dealers & Resellers ></option>
<option value="52524">Wholesale Lots ></option>
HERE_DOC;
}
post_categories.html
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
// Initialize the object:
var ajax = false;
// Create the object...
// Choose object type based upon what's supported:
if (window.XMLHttpRequest) {
// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
ajax = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Older IE browsers
// Create type Msxml2.XMLHTTP, if possible:
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) { // Create the older type instead:
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) { }
}
}
// Send an alert if the object wasn't created.
if (!ajax) {
alert ('Page functionality is unavailable. Update your browser.');
}
// Function that starts the Ajax process:
function categories_chain(username) {
// Confirm that the object is usable:
if (ajax) {
// Call the PHP script.
// Use the GET method.
// Pass the username in the URL.
ajax.open('get', 'categories.php?' + encodeURIComponent(username), true);
// Function that handles the response:
ajax.onreadystatechange = handle_check;
// Send the request:
ajax.send(null);
} // End of check_username() function.
// Function that handles the response from the PHP script:
function handle_check() {
// If everything's OK:
if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
// Assign the returned value to a document element:
document.getElementById('div2').innerHTML = ajax.responseText;
}
} // End of handle_check() function.
}
</script>
</head>
<body>
<form name="postadd">
<div id='div1'>
<select name="cat1" onChange='categories_chain(cat1.options[selectedIndex].value)'>
<option value="1">Antiques ></option>
<option value="2">Art ></option>
<option value="3">Automotive ></option>
</select>
</div>
<div id='div2'>
</div>
</body>
</html>
here is what i suggest:
<?php if(isset($_GET['1'])): ?>
<option value="1.1">Antiquities ></option>
<option value="1.2">Architectural & Garden ></option>
<option value="1.3">Asian Antiques ></option>
....
<?php elseif (isset($_GET['2'])): ?>
<option value="1.1">Antiquities ></option>
<option value="1.1">Antiquities ></option>
....
<?php endif;?>
This way your code is more organized and there is no less chance of errors
精彩评论