Forums

ajax error only in IE [solved]

gemlog 15 Sep, 2010
I'm pretty sure this is my problem and not anything to do with chronoforms at all. Or mootools. I'm just going crazy trying to spot the problem.

I have a multi "page" form where the first div is shown to get the user's postal code, this validates on key_up and works fine in all browsers I tried. I don't see what is syntactically different between what works fine in all browsers and what makes IE throw an error.

The first one looks like this and works in every browser including IE:
    window.addEvent('domready', function() {
    $('postalcode').addEvent('keyup', function() {
        var postalcode_v = $('postalcode').value;
        var url = window.location + '&task=extra&extraid=1&format=raw';
        var jSonRequest = new Json.Remote(url, {onComplete: function(postalcode){
        var el_log_res = document.getElementById('log_res');
        var el_mp_info = document.getElementById('mp_info');
        el_log_res.innerHTML = postalcode.log_res;
        if (postalcode.log_res == 'Valid'){
            el_log_res.style.color = 'green';
            $('postalcode').value = postalcode.postalcode;
            $('mp_info').setStyle('display', 'block');
            el_mp_info.innerHTML = '<br /><hr />Fetching MP information -- Please wait...';
            foo = fetchmp(postalcode.postalcode);
            }
        else {
            el_log_res.style.color = 'red';
            $('mp_info').setStyle('display', 'none');
        }
    }}).send({'postalcode': postalcode_v});
  });
});


As you can see, when the postal code is validated, it calls fetchmp() itself.

The second div gets shown after the mp is looked up. On FF, Konqueror and Chrome everything works fine. In IE I get Syntax Error, mootools.js line 80 char 52 and everything just stops at that point.

    function fetchmp(pcode) {
        var url = window.location + '&task=extra&extraid=2&format=raw';
        var el_mp_email = document.getElementById('mp_email');
        var jSonRequest2 = new Json.Remote(url, {onComplete: function(mp_scrape){
            var el_mp_info = document.getElementById('mp_info');
            el_mp_info.innerHTML = mp_scrape.mpinfo;
            var fname = document.getElementById('mp_fullname');
            fname.innerHTML = mp_scrape.fullname;
            var pmail = document.getElementById('mp_parlmail');
            pmail.innerHTML = mp_scrape.parlmail;
            $('email_to').value = mp_scrape.parlmail;
            var prov = document.getElementById('prov');
            if (mp_scrape.prov) {
                prov.value = mp_scrape.prov;
            }
            var city = document.getElementById('ucity');
            if (mp_scrape.city) {
                $('ucity').value = mp_scrape.city;
            }
        }}).send({'mp_scrape': pcode});
    }


The url for extraid=2 does get hit (I can see it in the server logs), but then under IE everything just comes to a stop on that syntax error I can't spot anywhere. Since the url does get hit, I suppose it happens on the return, but what?? The return from extraid=2 is just the usual 'echo json_encode($data)' This is what's in $data:

    $data->postalcode = $postal;
    $data->log_res = $pcodevalid;

 if ($pcodevalid == 'Valid') {
    $mpinfo = scrape_feds($postal);
    $data->mpinfo = $mpinfo['html'];
    $data->fullname = $mpinfo['fullname'];
    $data->parlmail = $mpinfo['parlmail'];
    $data->prov = $mpinfo['prov'];
    $data->city = $mpinfo['city'];
} else { ...


I've been using it for months on and off under firefox and had no idea it was broken in any way until I tried to use it with IE. I'm hoping one of you guys is so steeped in this stuff that a quick glance at it will tell you where I messed up.
GreyHead 16 Sep, 2010
Hi gemlog,

No real idea - there might be a clue here

Bob
gemlog 17 Sep, 2010
Wow. If you don't know either I'm really worried now! :-(

Thanks for finding that. The only other one I saw was wrt css. I will go looking for possible null values.

I thought css probs were a good enough reason to hate IE. I guess I was wrong.
mesothelioma 17 Sep, 2010

Hi gemlog,

No real idea - there might be a clue here

Bob



Thanks Bob. And nope, there are MANY MANY reasons to hate IE.
gemlog 21 Sep, 2010
I am going mad.
Pounding my forehead flat on the desk for several days now.

The specific error is only on the net in a few places and no one fixed it -- just changed to something else, which I can't do.

I looked for any trailing commas in lists, nulls etc as suggested in a few places for other, similar errors. I swapped out the template to a joomla default. Turned off various site modules. Removed some other js in there I have for a city look-up autocompleter. Although it points to a .js problem, I still went through all my php and html. I've tried it with and without behaviour::mootools being explicit. Heck, I dunno, just hours and hours worth of stuff that made no difference to IE!

I have been working on it on and off for almost a year now and I finally got it all together until IE got in the way. This is the actual reason I installed CF.

I would guess that people who work in IE have tools/methods that I don't have or even know of for debugging? Also different eyeballs. I've disabled the part where it would actually email a Member of Parliament, but there's no need to go that far as it doesn't get past step one after entering a postal code in IE, but works fine in FF from end to end.

http://arpacanada.ca/index2.php?option=com_chronocontact&chronoformname=pcode_52
Index2 makes it look a little funny, but it eliminates any other clutter and modules.
A1A1A1 is a valid Cdn postal code with an MP. Just typing those 6 letters in ie will trigger the bug.

I really hope someone can spot just what it is IE is objecting to as I'm at my wit's end.
iamobama 21 Sep, 2010
IE6.0? IE7.0?IE8.0?
gemlog 21 Sep, 2010
7 and 8 for sure.
gemlog 24 Sep, 2010
I've since gone through a lot of different things and discovered (I think) that it is somehow to do with how I either call the second function or how I set that f() up, because it doesn't matter at all what is in the second one (e.g. a = 5;), it still breaks. It also doesn't matter what I send back from the php as I tried setting everything to just strings like $data->mpinfo = 'foo1' rather than the vars that it really needs.

I also tried inserting the second json request into the first, working, function. Likewise I tried calling it from a third dummy function to no avail.

Here's all it needs to be in order to have the problem. Maybe it is easier for someone to spot what I'm doing wrong or can suggest a different way to call it.
    window.addEvent('domready', function() {
    $('postalcode').addEvent('keyup', function() {
        var postalcode_v = $('postalcode').value;
        var url = window.location + '&task=extra&extraid=1&format=raw';
        var jSonRequest = new Json.Remote(url, {onComplete: function(postalcode){
        el_log_res.innerHTML = postalcode.log_res;
        if (postalcode.log_res == 'Valid'){
            foo = fetchmp(postalcode.postalcode);
            }
        else {
            el_log_res.style.color = 'red';
            $('mp_info').setStyle('display', 'none');
        }
    }}).send({'postalcode': postalcode_v});
  });


This is the fetchmp() it calls on 'Valid' input:

    function fetchmp(pcode) {
        var url = window.location + '&task=extra&extraid=2&format=raw';
        var jSonRequest2 = new Json.Remote(url, {onComplete: function(mp_scrape){
        [boring stuff that has no effect at all]
        }}).send({'mp_scrape': pcode});
    }
GreyHead 24 Sep, 2010
Hi gemlog,

Been away for a few days. Back now, I'll try to take a look and see if I can spot anything.

Bob
gemlog 24 Sep, 2010
Thanks very much Bob. I'd be grateful for *any* insights. I've tried all kinds of strange things and I'm quite far 'out in the weeds' by now with the things I'm trying.

edit: still no joy. my next idea is to try a work-a-round by making a hidden input field and triggering the f() manually with onChange. All I can think of by now. Hope you have something cleaner that makes sense -- not that my latest idea will work necessarily ... Or that IE makes sense.
GreyHead 25 Sep, 2010
Hi gemlog,

The error seesm to be conencted to writing values in a cookie. I wonder if it is because you have the JSON calls nested one inside the other?

Bob
gemlog 25 Sep, 2010
Thanks Bob,

I'm not explicitly writing to a cookie anywhere -- or where did you see that? I do write to a tmp file, but only on the server side.

The onChange idea is an attempt to disconnect the two, but it was just another idea until your comment reinforced it. I still don't see why it would be a problem. The longer I'm at this, the more IE seems like voodoo...

I looked at mootool's Chain yesterday, but that runs on delay. Is there a better way to do it than putting [some_element].onchange() inside f1() after I set [some_element]? Somehow f2(arg from f1) must run only after f1() completes.
GreyHead 25 Sep, 2010
Hi gemlog,

I looked at the code with Companion.JS in IE8 and the highlighted line in MooTools was about saving to a cookie.

Bob
gemlog 25 Sep, 2010
Well, the onchange idea works just fine -- but not in IE :-( Same error as always.
The highlighted bit in the IE8 debugger is actually

{return(($type(str)!='string')||(secure&&!str.test(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/)))?null:eval('('+str+')');}};


In other langs I've used, things often break on the instruction just before the real problem. The next part is:

Json.Remote=XHR.extend({initialize:function(url,options){this.url=url;this.addEvent('onSuccess',this.onComplete);this.parent(options);this.setHeader('X-Request','JSON');},send:function(obj){return this.parent(this.url,'json='+Json.toString(obj));},onComplete:function(){this.fireEvent('onComplete',[Json.evaluate(this.response.text,this.options.secure)]);}});


I don't see anything for cookies until line 81. But I'm lost in the obfuscated js anyhow. I did try using the other compressor and the uncompressed version as well.

I really had high hopes for the onchange idea decoupling them. When I eventually find the problem, I just know it's going to very, very trivial.
gemlog 28 Sep, 2010
Among some other attempts today, I made a button to call the second function directly:
<input type="button" name="ie_pcode" id="ie_pcode" value="ie_pcode" onclick="fetchmp('A1A1A1');return false;" />

And IE Still returns the same syntax error line 80 char 52. There must be something it doesn't like about the answer from the server?, but I have no idea what.

    $data->postalcode = $postal;
    $data->log_res = $pcodevalid;

 if ($pcodevalid == 'Valid') {
    $mpinfo = scrape_feds($postal);
    $data->mpinfo = $mpinfo['html'];
    $data->fullname = $mpinfo['fullname'];
    $data->parlmail = $mpinfo['parlmail'];
    $data->prov = $mpinfo['prov'];
    $data->city = $mpinfo['city'];
} else {
    $data->mpinfo = $ret_fail;
    $data->fullname = '';
    $data->parlmail = '';
    $data->prov = '';
    $data->city = '';
}

// encode and return the result
echo json_encode($data);
gemlog 28 Sep, 2010
Incredibly, ie was trying to eval an html comment in my extra-code2 -- it took that as the name of the array for some reason. Then I think it choked on the white space after the line (CR/LF pair). Bizarre waste of time. I thought I couldn't dislike IE more, but I was wrong.

Thanks very much for encouraging me along bob. I was going nuts there.
GreyHead 28 Sep, 2010
Hi gemlog,

Well done - I too hate debugging JavaScript in IE - maybe IE9 will be better!

Bob
gemlog 28 Sep, 2010
We live in hope! :-)

The good news is that usage of all versions of IE is still dropping. I think it's down to around half now.
This topic is locked and no more replies can be posted.