使用google.com/tbproxy/spell进行拼写检查


spell check using google.com/tbproxy/spell

我在我的项目中使用谷歌拼写检查,并按照博客中建议的做一切,但它似乎不适合我。你能看看这个,告诉我我做错了什么吗?

在我的JavaScript:

function makeRequest(parameters, svalue) {  
  console.log("dv-- inside makerequest 1");
  console.log("svalue =", svalue);
  http_request.onreadystatechange = GetResponse;
  http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en', true);    
  data = '<?xml version="1.0" encoding="utf-8" ?>';
  data +='<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>';
  data += svalue;
  data += '</text></spellrequest>';
  console.log("data =", data)
  http_request.send(data);
}
function GetResponse(){
  console.log("dv-- inside GetResponse-1 http_request.readyState =", http_request.readyState)
  if (http_request.readyState == 4) {
console.log("dv-- inside GetResponse-2 http_request.status =", http_request.status)
    if (http_request.status == 200) {
  http_response = http_request.responseText;
  console.log("dv --http_response =", http_response)
    }
    else {
      console.log('There was a problem with the request' + '& http_request.status =' + http_request.status );
    }
  }
}

我的PHP代码:spelllifp . PHP

$url="http://www.google.com/tbproxy/spell?lang=en&hl=en";
//$data = file_get_contents('php://input');
$data = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hellow  </text></spellrequest>';
$data = urldecode($data);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch); 
print $contents;
?>

我尝试硬编码的数据在我的php,以确保数据被正确传递,这不是一个问题。

Firefox给出一个错误:Error: unclosed token 源文件:http://mysite.com/Project/spellify.php?lang=en 行:5,列:183Source Code: $ data = '<?xml version="1.0" encoding="utf-8" ?>< spellrequest=" texttalreadyclipped="0" ignoredps="0" ignoredigits="0" ignoreallcaps="0"> & lt; '/spellrequest">,

Chrome没有给出任何错误,但在控制台显示如下:

dv-- inside makerequest 1
spellify.js:419svalue = hello worlda 
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 1
spellify.js:427data = <?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hello worlda </text></spellrequest>
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 2
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 3
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 4
spellify.js:435dv-- inside GetResponse-2 http_request.status = 200
spellify.js:438dv --http_response = <?php
$url="http://www.google.com/tbproxy/spell?lang=en&hl=en";
// $data = file_get_contents('php://input');
$data = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hello thsi is graet</text></spellrequest>';
$data = urldecode($data);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
$contents = curl_exec ($ch);
curl_close ($ch); 
print $contents;
?>

请建议哪些地方可以改正以使此工作。

谢谢

您正在使用来自spelllify.com的代码,感谢原始开发人员的某种荣誉。

1)您错误地修改了spelllifp .php文件。2-a) Spellify基本上是通过Javascript src/Spellify .js准备http-request和解析http-response,所以在Spellify .php中做任何改变都是不正确的,而你应该检查你是否正确引用了Spellify/src/scriptaculouss .js和Spellify/src/prototype.js。

2-b)在相同的拼写.js下,你已经硬编码了下面的行不正确;

http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en', true);

应该如下所示;

http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en'+parameters, true);

3)写spelllify .php的时候,SSL验证可能没有问题,但现在它不会返回任何东西,除非你忽略SSL验证,在spelllify .php中添加以下行,在$contents = curl_exec ($ch);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

下面是示例实现。

http://amitgandhi.in/2013/01/25/spell-check-utility-using-jquery-and-google-api/

  • 可以添加单词字典。变量$.SpellChecker.dicWords是aJavascript数组来维护这个。您可以使用数据库表用现有的单词填充这个数组。目前这个应用程序不是连接到数据库,所以如果你添加你的词,那么生命周期的词直到页面重新加载。

  • 使用google.com/tbproxy/spell api调用(PHP编写)