Javascript 调用Servlet时Jquery Ajax函数不起作用

Javascript 调用Servlet时Jquery Ajax函数不起作用,javascript,jquery,ajax,servlets,Javascript,Jquery,Ajax,Servlets,我在调用ajax时遇到了一些问题。有人能看看我的代码并提出一些解决我问题的建议吗 function search(file,input){ $.ajax({url:'/Searchandhighlight?name='+input+'&file='+file,type:"post", success:function(){ $("#bodyy").html(); } });

我在调用ajax时遇到了一些问题。有人能看看我的代码并提出一些解决我问题的建议吗

function search(file,input){
      $.ajax({url:'/Searchandhighlight?name='+input+'&file='+file,type:"post",
              success:function(){
                 $("#bodyy").html();
              }
    });
   }
我使用ajax调用servlet,servlet更改了数据库的一些内容,成功后,我尝试刷新我的“#bodyy”div


提前感谢

首先让我们知道文件变量所包含的内容

通常带有参数的Ajax调用是这样的<代码>数据类型取决于您期望的响应类型

 $.ajax({
                type: "POST",
                url: "/Searchandhighlight",                
                dataType: "json",
                data: {"name" : input, "file" : file},
                success:function(data){
                    if(data){
                        alert("success");
                    }
                },
                error:function(){
                    alert('failed');
                } 

            })   

我最终通过以下代码解决了我的问题

    function search(file,input){
      if(input != "") {
       xmlhttp = new XMLHttpRequest();
        xmlhttp.open("POST", "/Searchandhighlight?name=" + input + "&file=" + file, true);
        xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            window.location.reload();
          }
       }
        xmlhttp.send(null);
      }
   }

文件包含哪些参数?它包含文件名,如“C:\apache-tomcat-7.0.63\webapps\data\Airline Ticketing\意大利语VAT\hello.txt”和“输入”保持文本框中的字符串OK…你可以尝试下面的代码,让我们知道是否打印成功。它根本没有调用servlet。我试图在ajax调用它之前打印一些值,但它会在ajax调用时卡住。通过硬编码的数据查看它是否正在调用servlet。比如{“Name”:“person”,“file”:“TBD”}和test,否则我怀疑URL没有指向正确的位置。嘿,我正在打印一些hello字符串,让大家知道servlet是否被调用。但它并没有打印hello字符串,这意味着并没有调用Servlet。好的,请通过这个链接,检查您的Servlet并让它工作。