Function

$().SPServices

Web Service

SpellChecker

Operation

SpellCheck

Example

This is adapted from an example by TechnSmile in this discussion thread.


var chunks = "Thhank yoou Marck ;)".split(" ");

for (i=0; i<chunks.length; i++){
  chunks[i] = "<string>" + chunks[i] + "</string>";
}

var spellResults;
$().SPServices({
  operation: "SpellCheck",
  chunksToSpell: chunks, 
  declaredLanguage: 1033, // use 1033 for english
  useLad: false,
  completefunc: function(xData, Status){
    alert(xData.responseText)
  }
});

Last edited Mar 9, 2013 at 9:00 PM by sympmarc, version 2

Comments

bill_rishsew Mar 14, 2013 at 7:31 PM 
As an after thought, perhaps I should explain what I hope to accomplish to ensure I'm using the right tool. I just want the web service to tell me if there are any misspelled words when the form submission button is pressed. If there are misspelled words, my code with call the SP Spell Checker.

bill_rishsew Mar 14, 2013 at 7:23 PM 
I took another look at the Web Service definition on MSDN and saw that the chunksToSpell expects a System.String type. So, I rewrote the code to look like this (same error :():

function spellChecker(str) {
var strTemp = str;
var aryChunks = [];
var strChunks = '';
var intArrayLength = 0;
var spellResults = '';

strTemp = str.replace(/\r?\n|\r/g, ' ');
aryChunks = strTemp.split(" ");
intArrayLength = aryChunks.length;

for(var i = 0; i < intArrayLength; i++){
if(aryChunks[i] != '') {
strChunks += "<string>" + aryChunks[i] + "</string>";
}
}

$().SPServices({
operation: "SpellCheck",
chunksToSpell: strChunks,
declaredLanguage: 1033,
useLad: false,
completefunc: function(xData, Status){
alert(xData.responseText);
}
});
}

bill_rishsew Mar 14, 2013 at 6:46 PM 
Not sure how old this content is, but I'm experiencing an issue.
I recieve an error message telling me:

Server was unable to process request. ---&gt; Name cannot begin with the '&lt;' character, hexadecimal value 0x3C.

Here is my code:

function spellChecker(str) {
var strTemp = str;
var aryChunks = [];
var aryChunks2 = [];
var intArrayLength = 0;
var spellResults = '';

strTemp = str.replace(/\r?\n|\r/g, ' ');
aryChunks = strTemp.split(" ");
intArrayLength = aryChunks.length;

for(var i = 0; i < intArrayLength; i++){
if(aryChunks[i] != '') {
aryChunks2.push("<string>" + aryChunks[i] + "</string>");
}
}

$().SPServices({
operation: "SpellCheck",
chunksToSpell: aryChunks2,
declaredLanguage: 1033,
useLad: false,
completefunc: function(xData, Status){
alert(xData.responseText);
}
});
}