自动完成错误出现在jsp/ajax中 [英] autocomplete error coming in jsp/ajax

查看:102
本文介绍了自动完成错误出现在jsp/ajax中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// index.jsp

<html>
 <head>
 <title>JSP page</title>
<script="text/javascript">
$(function() {
// subscribe to the keydown event
$('#text1').keydown(function(e) {
    // when a key is pressed check if its code was 9 (TAB)
    if (e.which == 9) {
        // if TAB was pressed send an AJAX request
        // to the server passing it the currently 
        // entered value in the first textbox
        $.ajax({
            url: '/someservlet/',// i have created a servlet named as someservlet
            type: 'POST',
            data: { value: $(this).val() },
            success: function(result) {
                // when the AJAX succeeds update the value of the 
                // second textbox using the result returned by the server
                // In this example we suppose that the servlet returns
                // the following JSON: {"foo":"bar"}
                $('#text2').val(result.foo);
            }
        });    
    }
});
});
</script>
</head>
<input type="text" id="text1" name="firsttextbox"/>
<input type="text" id="text2" name="secondtextbox"/>
<body>

//执行post()someservlet

String dd = request.getParameter("firsttextbox"); 
String json = new Gson().toJson(options);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);

我是否需要在head块中导入任何js文件?谁能告诉我我错了吗?编译时出现jsper ...错误.相同的代码正在摆弄:

Do i need to import any js file inside head block? Can anyone tell me where i am wrong? While compiling i am getting the jsper...error. Same code is working in fiddle:

http://jsfiddle.net/JLJ3f/

在netbeans中编译时,出现错误.

While compiling in netbeans, i am getting error.

感谢您的帮助.

推荐答案

您正在使用jquery函数,但是您的html页面中没有jquery库, 在小提琴中,您可以将其导入到左框架中的选定框架菜单下,

you are using jquery functions but you don have jquery library in your html page, in fiddle you can import it in your left frame, under chose framework menu,

info:以下是不同的CDN

info:following are the different CDN

  • Google Ajax API CDN (Also supports SSL via HTTPS) o http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js o Google Ajax CDN Documentation
  • Microsoft CDN (Also supports SSL via HTTPS) o http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js o Ajax CDN Announcement, Microsoft Ajax CDN Documentation
  • jQuery CDN (via Media Temple) o http://code.jquery.com/jquery-1.7.1.min.js Minified version o http://code.jquery.com/jquery-1.7.1.js Source version

,因此您可以通过<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>添加它 或者 在本地下载并将其链接到您的html页面

so you can add it through <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> or download it locally and link it to your html page

这篇关于自动完成错误出现在jsp/ajax中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆