Hi everyone

I've been working on an ajax call which activates a spellchecker when
someone inputs a word (if it's incorrect) and returns a Json string of
suggestions for the user to choose from, and then be able to replace
the incorrect word.

It seems to work the first couple of times but then Safari will hang
and finally quit. I'm not sure what I've done wrong, but for some
reason the console on FF doesn't register the call so I'm assuming
something else is causing a problem - unless there's a compatibility
issue with jQuery on Safari 4.

Here's my function that calls the spellchecker (Sorry it's a bit
long!)


/**************************************************************/

var SpellCheckOptions = { learn : false, serverScriptURL :
'spellchecker.php' };

function checkSpelling(type,targetId,exists,len,ulen) {
        var theid = "#"+targetId;
        var $spellcheckthis = $(theid);
        var thetext = $spellcheckthis.text();

        var callback = function(textInfos) {
        if(type=="textarea"){
                $("form")[0].reset(); // reset textarea content before 
populating it
with the edited text
        }
          $spellcheckthis.text(textInfos[0].text);
                if(type=="word"){ // if we're spell checking a word/phrase
                if(exists == false){ // if that word doesn't exist in the
userwords array

                                if(len<6){
                                        
words[targetId][1].push(textInfos[0].text);

                                        var userwordexists = false;
                                                for(var u=0;u<ulen;u++){
                                                        if(userwords[u][0] == 
targetId){
                                                                userwords[u][1] 
= textInfos[0].text;
                                                                userwordexists 
= true;
                                                        }
                                                }
                                                if(userwordexists == false){ // 
i.e. the id was not present in
the userwords array...
                                                        userwords.push(new 
Array(targetId, textInfos[0].text)); //
create a new level to the userwords array.
                                                }
                                }else{
                                        
words[targetId][1].splice(0,1,textInfos[0].text);

                                        var userwordexists = false;
                                                for(var u=0;u<ulen;u++){
                                                        if(userwords[u][0] == 
targetId){
                                                                userwords[u][1] 
= textInfos[0].text;
                                                                userwordexists 
= true;
                                                        }
                                                        userwords[u][1] = 
textInfos[0].text;
                                                }
                                }
                        }return false;

                }else{ // it's a textarea, so no templated userwords need to be
saved.
                        alert("Spellcheck complete. Profile saved.");
                }
        }// end call back

jQuery.ajax({ // send details to server
    type : 'POST',
    dataType : 'json',
    url : SpellCheckOptions.serverScriptURL,
    data : { words : thetext },
    success : function(result) { if(result) { console.log(result);
SpellCheckOptions.useServer=result;
    var spellcheck = JQSpellCheckDialog.create({text : thetext},
callback, SpellCheckOptions);
        spellcheck.open(); }else{if ( (!type)|| (type==undefined) ){if(exists
== false){if(len<6){words[targetId][1].push(thetext);
        var userwordexists = false;for(var u=0;u<ulen;u++){if(userwords[u][0]
== targetId){userwords[u][1] = thetext;
        userwordexists = true;}}if(userwordexists == false){userwords.push
(new Array(targetId, thetext));}
        }else{words[targetId][1].splice(0,1,thetext);userwords[targetId][1] =
thetext;}}}else{
        if(type=='textarea'){alert("Spellcheck complete. Profile
saved.");}}}// end success function.
        }});// end ajax call

}

/**************************************************************/

Of course, it may be another part of this function which is causing
the hang - although like i say it works the first time around. Plus
it's absolutely fine in FF and IE...

Thanks for reading
Mike

Reply via email to