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

发布于 2024-11-30 03:39:32 字数 5645 浏览 6 评论 0原文

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

在此处输入图像描述

有人建议我如何解决它。

点击此处查看示例

PS:

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

LINK:

<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/';
}

CheckSpelling.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");
}

I tried to implement Jquery.Spell.Checker in asp.net application but it gives error as shown in following image.

enter image description here

Anyone suggest me how to resolve it.

CLICK HERE TO SEE THE SAMPLE

PS:

I have done changes in my application but still doesn't working and display alert message as per above image.Please let me know if i was missing something.The code given below:

LINK:

<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> 
        <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/';
}

CheckSpelling.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");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

反差帅 2024-12-07 03:39:32

您需要自己编写一个包含 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”

You need to write yourself an ASP version of the included PHP server side file. Essentially, the server side component proxies a request off to Google or uses a PHP spell checker. Since you wouldn't really want to convert the whole of the Pspell library, I would recommend simply wrapping up the call to Google's spell check site.

i.e. Create an ASPX page and add the following code to it

<%@ 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>

Then change the call in the js to call your new aspx file rather than the 'checkspelling.php'

妳是的陽光 2024-12-07 03:39:32

对你来说可能有点晚了,但对于任何试图解决这个问题的人来说,Jack Yang 已经制作了一个 checkpelling.php 的 ASP 实现,可以在

https://github.com/jackmyang/jQuery-Spell-Checker-for-ASP.NET

Might be a bit late for you, but for any one else trying to resolve this problem, Jack Yang has produced an ASP implementation of checkspelling.php it can be found at

https://github.com/jackmyang/jQuery-Spell-Checker-for-ASP.NET

风和你 2024-12-07 03:39:32

该插件仅执行客户端代码。您必须向它提供 ASP 脚本的 URL。

阅读文档

The plugin only does the client-side code. You'll have to supply it with your ASP script's URL.

Read the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文