PDA

View Full Version : Ajax not sending in IE7


fsstore.net
01-02-2008, 04:50 AM
Hi everyone.

I am using the Ajax tutorial from ajaxfreaks, here is the JS:
<script type="application/javascript" language="javascript">
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('Problem creating the XMLHttpRequest object');
}
return req;
}

// Make the XMLHttpRequest object
var http = createRequestObject();
function sendRequest(act) {

// Open PHP script for requests
http.open('get', '_includes/_submit_airport.php?+act);
http.onreadystatechange = handleResponse;
http.send(null);

}

function handleResponse() {

if(http.readyState == 4 && http.status == 200){

// Text returned FROM the PHP script
var response = http.responseText;

if(response) {
// UPDATE ajaxTest content
document.getElementById("airportBox").innerHTML = response;
}
}
}
</script>


And this is how I am using it:
<input type="button" name="submit" id="submit" value="Add" onClick="sendRequest('name=' + airport.name.value + '&country=' + airport.country.value + '&state=' + airport.state.value + '&city=' + airport.city.value + '&icao=' + airport.icao.value);" />

So basically it sends some data which will eventually look like:
_submit_airport.php?name=x&country=x&state=x... etc.

Everything works flawlessly in Firefox, Opera, and Safari, but not in IE7 (haven't tried IE6 yet). All it says is that there is an error on the line of the second code I posted, Character 1, and the error is "Object Expected".

Any ideas?
Thanks

arilia
01-02-2008, 11:51 AM
Seems ok. The only error I get is

http.open('get', '_includes/_submit_airport.php?+act);

where a ' is missing.

http.open('get', '_includes/_submit_airport.php?' + act);

arilia
01-02-2008, 12:09 PM
ok, the problem seems to be here

<script type="application/javascript" language="javascript">

instead of

<script type="text/javascript" >

don't' ask me why!

fsstore.net
01-02-2008, 02:24 PM
Hi,

Sorry. The first missing tic mark was an error on my part copy and pasting. The actual code does have it.

I took out the "language="javascript"" part and still does the same thing. :( Here is the URL, I am sure it will help:
http://www.fszone.org/logbook/add/airport.php

arilia
01-02-2008, 02:30 PM
the problem is not in language="javascript" (that is deprecated but not wrong)

the question seems to be in

type="application/javascript"

instead of

type="text/javascript"

fsstore.net
01-02-2008, 02:37 PM
the problem is not in language="javascript" (that is deprecated but not wrong)

the question seems to be in

type="application/javascript"

instead of

type="text/javascript"

Whoops, sorry about that! Yeah, that was it! Thanks for the help, I would have never thought about looking there.