【问题标题】:send parameter from js file to jsp file with ajax使用ajax将参数从js文件发送到jsp文件
【发布时间】:2018-02-05 00:18:49
【问题描述】:

这是我的 js 文件,我的目标是将变量 va 发送到 jsp 文件并输出。问题我找不到错误。

 $(function(){
    $("td").click(function(){

        var date = $(this).html();
        var message = prompt(year+"year "+month+"month "+ date+"day","null!");
        this.append(message);   
        var variable = "mememem";
        var sendData = new XMLHttpRequest();
        sendData.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
              alert("connected to server");
            }
          };

        sendData.open('GET','dataFile.jsp?na='+variable,true);
        sendData.send(null);
        window.location = "dataFile.jsp"; 

    })
});

///////////////////////javascript 文件//////////////// ////

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String name = request.getParameter("na");

out.print(name);
%>
</body>
</html>

////////////////jsp文件

【问题讨论】:

  • 什么“错误”?出了什么问题?有什么错误?
  • @Pointy request.getParameter("na");发出 null

标签: javascript ajax jsp


【解决方案1】:

我认为问题在于您发送的是 variable 而不是 va

这一行:

sendData.open('GET','dataFile.jsp?na='+variable,true);

希望这是您问题的根本原因。

【讨论】:

  • @Denico no va 不是问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-28
  • 2014-07-09
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多