gpt4 book ai didi

javascript - 如何解决在 .net 应用程序中实现 Jquery.SpellChecker 时出现的错误

转载 作者:行者123 更新时间:2023-12-02 20:09:23 25 4
gpt4 key购买 nike

我尝试在 asp.net 应用程序中实现 Jquery.Spell.Checker,但它给出了错误,如下图所示。

enter image description here

有人建议我如何解决这个问题。

CLICK HERE TO SEE THE SAMPLE

附注:

我已经在我的应用程序中进行了更改,但仍然无法工作并按照上图显示警报消息。如果我丢失了某些内容,请告诉我。下面给出的代码:

链接:

<link href="JQuerySpellChecker/spellchecker.css" rel="stylesheet" type="text/css" />
<script src="JavaScript/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="JQuerySpellChecker/jquery.spellchecker.js" type="text/javascript"></script>

CSS:

<style type="text/css">
body {
margin: 1em;
font-family: 'lucida grande',helvetica,verdana,arial,sans-serif;
}
#textarea-example {
width: 562px;
}
textarea {
font-size: 90%;
margin-bottom:10px;
padding: 5px;
border: 1px solid #999999;
border-color: #888888 #CCCCCC #CCCCCC #888888;
border-style: solid;
height: 20em;
width: 550px;
}
button {
font-size: 90%;
cursor: pointer;
}
.loading {
padding: 0.5em 8px;
display: none;
font-size: small;
}
</style>

HTML:

<div id="textarea-example">
<p>
<label for="text-content">Add your own text and check the spelling.</label>
</p>
<textarea id="text-content" rows="5" cols="25"></textarea>
<div>
<button id="check-textarea">Check Spelling</button>&nbsp;
<span class="loading">loading..</span>
</div>
</div>

JAVASCRIPT:

// check the spelling on a textarea
$("#check-textarea").click(function(e){
e.preventDefault();
$(".loading").show();
$("#text-content")
.spellchecker({
url: "CheckSpelling.aspx", // default spellcheck url
lang: "en", // default language
engine: "google", // pspell or google
addToDictionary: false, // display option to add word to dictionary (pspell only)
wordlist: {
action: "after", // which jquery dom insert action
element: $("#text-content") // which object to apply above method
},
suggestBoxPosition: "below", // position of suggest box; above or below the highlighted word
innerDocument: false // if you want the badwords highlighted in the html then set to true
})
.spellchecker("check", function(result){
// spell checker has finished checking words
$(".loading").hide();
// if result is true then there are no badly spelt words
if (result) {
alert('There are no incorrectly spelt words.');
}
});
});
// you can ignore this; if document is viewed via subversion in google code then re-direct to demo page
if (/jquery-spellchecker\.googlecode\.com/.test(window.location.hostname) && /svn/.test(window.location)) {
window.location = 'http://spellchecker.jquery.badsyntax.co.uk/';
}

拼写检查.aspx

protected void Page_Load(object sender, EventArgs e)
{
string str = Request["str"];
//string str = "goood";
if (str != null)
{
string url = "https://www.google.com";
string path = "/tbproxy/spell?lang=en&hl=en";
// setup XML request
string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
xml += "<spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" ignoreallcaps=\"1\">";
xml += "<text>" + str + "</text></spellrequest>";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(xml);
WebProxy objWP = new WebProxy("address", 1978);
objWP.Credentials = new NetworkCredential("mysystemname", "password");
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url + path);
request.Proxy = objWP;
request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = data.Length;
System.IO.Stream stream = request.GetRequestStream();
// Send the data.
stream.Write(data, 0, data.Length);
stream.Close();
// Get the response.
System.Net.WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
stream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Clean up the streams.
reader.Close();
stream.Close();
response.Close();
Response.ContentType = "text/xml";
MatchCollection result = Regex.Matches(responseFromServer, "<c o=\"([^\"]*)\" l=\"([^\"]*)\" s=\"([^\"]*)\">([^<]*)</c>");
if (result != null && result.Count > 0)
Response.Write(result[0].Value);
}
Response.Write("Failed");
}

最佳答案

您需要自己编写一个包含 PHP 服务器端文件的 ASP 版本。本质上,服务器端组件将请求代理给 Google 或使用 PHP 拼写检查器。由于您并不真正想要转换整个 Pspell 库,因此我建议简单地结束对 Google 拼写检查站点的调用。

即创建一个ASPX页面并添加以下代码

<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">
public void Page_Load(Object src, EventArgs e)
{
var str = Request["str"];
if (str != null)
{
var url = "https://www.google.com";
var path = "/tbproxy/spell?lang=en&hl=en";

// setup XML request
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
xml += "<spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" ignoreallcaps=\"1\">";
xml += "<text>" + str + "</text></spellrequest>";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(xml);

System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url + path);
request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = data.Length;
System.IO.Stream stream = request.GetRequestStream();

// Send the data.
stream.Write(data, 0, data.Length);
stream.Close();

// Get the response.
System.Net.WebResponse response = request.GetResponse();

// Get the stream containing content returned by the server.
stream = response.GetResponseStream();

// Open the stream using a StreamReader for easy access.
System.IO.StreamReader reader = new System.IO.StreamReader(stream);

// Read the content.
string responseFromServer = reader.ReadToEnd();

// Clean up the streams.
reader.Close();
stream.Close();
response.Close();

Response.ContentType = "text/xml";
MatchCollection result = Regex.Matches(responseFromServer, "<c o=\"([^\"]*)\" l=\"([^\"]*)\" s=\"([^\"]*)\">([^<]*)</c>");
if (result != null && result.Count > 0)
Response.Write(result[0].Value);
}
Response.Write("Failed");
}
</script>

然后更改 js 中的调用以调用新的 aspx 文件而不是“checkspelling.php”

关于javascript - 如何解决在 .net 应用程序中实现 Jquery.SpellChecker 时出现的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com