Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 简单(或可能不是)JSP测试页面_Javascript - Fatal编程技术网

Javascript 简单(或可能不是)JSP测试页面

Javascript 简单(或可能不是)JSP测试页面,javascript,Javascript,我有一个这样的测试页面 <%@ page contentType="text/html; charset=UTF-8"%> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0" > <tr> <td width="50%">&nbsp;</td> <td

我有一个这样的测试页面

<%@ page contentType="text/html; charset=UTF-8"%>
<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>

服务(正确/错误)检查
回应

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>
我导入JQuery文件和我的JS文件

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>
testPage.js

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>
        function trueFalseLookup()
    {
        var strToCheck = $('#trueFalseInput').val();

        $.getJSON( 'myService?text='+ strToCheck +'&type=exists'  ).
                success( trueFalseResponse ).
                error( function ()
        {
            $('#trueFalseResult').val("Error calling my service");
        });
    }

    function trueFalseResponse( data )
    {
        $('#trueFalseResult').val('');

        if( data.error )
        {
            $('#trueFalseResult').val('Error: ' + data.errorMessage );
        }
        else
        {
            for( var i=0; i < data.results.length; i++ )
            {
                $('#trueFalseResult').val($('#trueFalseResult').val() +  '[' + data.results[i].word + ']: '+ data.results[i].homophone + '\n');
            }
        }
    }
函数trueFalseLookup()
{
var strToCheck=$('#trueFalseInput').val();
$.getJSON('myService?text='+strToCheck+'&type=exists')。
成功(真实的错误反应)。
错误(函数()
{
$('#truefalsesult').val(“调用我的服务时出错”);
});
}
功能响应(数据)
{
$('truefalsesult').val('';
if(data.error)
{
$('#trueFalseResult').val('错误:'+data.errorMessage);
}
其他的
{
对于(var i=0;i
当我从服务器提供JSP文件时,一切正常。 我的浏览器是否可以在本地c:/drive上打开此页面? 我可以使用HTTP url导入JQuery文件吗?我可以将Javascript粘贴到脚本标记之间的JSP文件中吗?

如何修改ajax服务器调用以调用“MyLocalHost”服务器

您混淆了为jQuery的Ajax调用提供的两个不同API。要么:

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>
// no failure API available, I believe, in this case.
$.getJSON( 'myService?text='+ strToCheck +'&type=exists', trueFalseResponse )

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>

您还可以通过basic
jQuery.ajax
调用来实现这一点;在这种情况下,您可以使用“success”属性名。但我认为第二个例子可以满足你的需要

如果页面由web服务器提供,则我的代码工作正常。我遇到的问题是$.getJSON('strToCheck+'&type=exists')。不起作用。显然,我没有正确地调用服务器,但我不知道如何做,很抱歉,显然我读得不够多。您应该能够从本地web服务器(Apache、IIS或更轻量级的服务器)上运行相同的功能,但许多浏览器的安全模型禁止对本地文件进行XHR调用。(如果您选择,您可以设置一个Chrome标志来允许此操作。)好的,所以
.success
.error
仍然存在,只是不推荐使用。即使它们仍然工作,您也可以考虑用<代码>替换它们。
<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
        <tr>
            <td width="50%">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>

        <tr>
            <td><H3>Service (True/False) check</H3></td>
            <td><H3>Response</H3></td>
        </tr>

        <tr>
            <td><textarea id="trueFalseInput" onkeyup="trueFalseLookup()" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
            <td><textarea id="trueFalseResult" style="margin-left:5px;width:300px;height:150px;" ></textarea></td>
        </tr>

    </table>
</body>