Go Back   The Liberty Lounge Political Forums > Liberty Lounge Community > The Speakeasy

Political Forum Click HERE to register your free account and become a member of our community today!
Register to Post a Reply
 
LinkBack Thread Tools
Old 09-18-2006, 03:29 PM   #1
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

Nerd Crew :: weird js issue with ff/ie

I've got this little AJAX applet I made. For some reason IE gives me a 'type mismatch error' if I put parentheses after http.onReadyStateChange = handleResponse (making it http.onReadyStateChange = handleResponse()). Any ideas on how to get this to work both ways without having to check for browser? Code is below. I'm aware that it's not really asynchronous with the 'false' parameter in the .open method but it won't work at all in FF without it there. I really just wanted to make a quick thing that didn't reload the page.

Code:
<script language="Javascript">
function createRequestObject() {
   var reqObj;

   if (window.ActiveXObject) {
        reqObj = new ActiveXObject("Microsoft.XMLHTTP");
    }//end if

   else if (window.XMLHttpRequest){
     reqObj = new XMLHttpRequest();
    }//end else if

    return reqObj;
} //end function

var http = createRequestObject();

function sndReq(action) {
    var str = "catName="+action.catBox.value;
    var file = "apDBSrch.php";
    http.open("POST", file, false);
    http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    http.send(str);
    http.onreadystatechange = handleResponse();
} // end function

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        } //end if

    } //end if

} //end function
</script>
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 03:48 PM   #2
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

I've never done any AJAX (though I have done a bit of java), so sorry if my questions are stupid.

What does handleResponse return? I mean, I don't see it giving you anything to actually set something else equal to. Maybe it's passing by reference and I just don't see it though
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 04:18 PM   #3
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

Yeah it doesn't actually return anything. It parses the return string and does the innerHTML change so the text shows up on the page. I don't understand exactly how it works tbh. If it were getting a value it would get null, I assume.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 04:19 PM   #4
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

I'm just saying, if it passes by reference, I don't see it, and it has to pass by SOMETHING for you to set something else equal to it.

So, what you're saying is, with the parens, it works find in ff, but not in ie? without, does it work in ie?
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 04:21 PM   #5
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

Without it works in IE, with it gives me a 'type mismatch' error but still works.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 04:24 PM   #6
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

can you try casting the handleResponse to http?
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 04:33 PM   #7
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

You can only typecast to number/string iirc.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 05:17 PM   #8
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

Originally Posted by beez View Post
You can only typecast to number/string iirc.
You can't cast to an object? I mean, in normal OOP languages, you make casting definitions within the object functions.

Can you call that line differently? Like I said, I've never programmed AJAX, so I don't even know why those parens are needed.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 05:24 PM   #9
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

Well, you don't need the parens in IE but you do for FF. I'm not sure why.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 05:28 PM   #10
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

I just asked one of my students (he's a programming genius). He says that since you're battling the ineffectiveness of javascript (not java), and you can't cast it void and recast it the correct type, you'll just have to do an ie hack (that is, make an if statment right at that line that is something like if browser = ie, do it one way, if browser = ff, do it another).

Sucks, but should be an easy fix.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 05:35 PM   #11
Member
 
beez's Avatar

libertarian
New York City, New York
beez has political potential

Yeah I figured I would have to do something like that. I wanted to see if there was a different way of fixing that up. Bah.

Thanks for puzzling through it with me
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 06:20 PM   #12
For those about to rock...
 
Ardentfrost's Avatar

libertarian
Atlanta, GA
Ardentfrost is the Vice President!Ardentfrost is the Vice President!

Originally Posted by beez View Post
Yeah I figured I would have to do something like that. I wanted to see if there was a different way of fixing that up. Bah.

Thanks for puzzling through it with me
np, sorry there wasn't a more elegant solution
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Old 09-18-2006, 09:28 PM   #13
Banned
 
ballz2wallz's Avatar

Conservative
Government is another way to say Better Than You
ballz2wallz has a spectacular aura about them

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble Upon this Post!
Register to Reply to This Post
Register to Post a Reply

Bookmarks

Tags
ffie, issue, weird, crew, nerd

Go Back   The Liberty Lounge Political Forums > Liberty Lounge Community > The Speakeasy



Thread Tools



SEO by vBSEO

vBulletin 3.7.4 -- Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. Custom Artwork and Theme (TM) 2006, Liberty Lounge