首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用google.com/tbproxy/spell进行拼写检查

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

Stack Overflow用户
提问于 2011-09-08 10:04:01
回答 2查看 3.7K关注 0票数 3

我在我的项目中使用谷歌拼写检查,并按照博客中的建议做了所有的事情,但它似乎对我不起作用。你能看看这个,告诉我我做错了什么吗?

在我的JavaScript中:

代码语言: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代码: spellify.php

代码语言:javascript
复制
$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中硬编码数据,以确保数据被正确传递,这不是问题。

ignoreallcaps="0"><text>hello thsi is graet</text><`/spellrequest>';给出错误:Error: unclosed token源文件:http://mysite.com/Project/spellify.php?lang=en行: 5,列: 183 Source Code: $data ='<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0“ignoredups="0”ignoredigits="0“Firefox

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

代码语言:javascript
复制
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;
?>

请建议可以进行哪些更正,以使此功能正常工作。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-26 18:51:12

您正在使用来自spellify.com的代码,感谢您对原始开发人员的某种信任。

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

2-b)在同一个spellify.js下,你硬编码下面的代码行不正确;

代码语言:javascript
复制
http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en', true);

应该是这样的:

代码语言:javascript
复制
http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en'+parameters, true);

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

代码语言:javascript
复制
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
票数 2
EN

Stack Overflow用户

发布于 2013-01-25 20:57:07

下面是示例实现。

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

  • 你可以添加单词字典。变量$.SpellChecker.dicWords是一个javascript数组,用来维护它。您可以使用您的数据库表将现有单词填充到此数组中。目前这个应用程序没有连接到数据库,所以如果你添加你的单词,那么单词的生命周期将只到页面重新加载。
  • 使用google.com/tbproxy/拼写api调用(用PHP编写)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7342393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档