有谁能告诉我如何将数据传递给进行AJAX调用的jsp?这就是我想要的:
这是我的AJAX电话:
$.get("gridedit.jsp", { before: "row", time: "2pm" })
.done(function(data) {
alert("Data Loaded: " + data);
});
这是我的gridedit.jsp
<% String b=request.getParameter("before");
if(b.equalsIgnoreCase("row"))
{
System.out.println("ROW ROW ROW your boat");
out.println("bummer");
} %>
我想将从gridedit.jsp返回的值存储到javascript变量中。我该怎么做?
请帮助
感谢
编辑:
这是我也尝试过的
$.ajax({
url: "gridedit.jsp",
async: true,
cache: false,
type:"GET",
data: {
before:'row',
},
error: function(msg) { alert(msg); },
complete: function (xhr, status) { alert('complete: '+status); }
});
我收到两个警报,第一个警告
[object][object]
,第二个说
error
任何人都可以知道发生了什么事吗?
请帮助
感谢
错误;
所以我在这里尝试了
$.ajax({
url: "gridedit.jsp",
//dataType: "json",
async: true,
cache: false,
type:"GET",
data: {
before:'row'
},
error: function( jqXHR, textStatus, errorThrown ) { alert(jqXHR);
alert(textStatus);
alert(errorThrown);},
complete: function (xhr, status) {
alert('jqXHR:'+xhr);
alert('complete: '+status); }
});
我按顺序收到以下警告:
jqXHR: [对象] [对象]
testStatus:
parseerror
errorthrown:
Unexpected end of input
任何人都可以帮我解决这个问题吗?我的gridedit.jsp执行此操作 - &gt;
<%String b=request.getParameter("before");
System.out.println("b is here !" + b);
out.println("HELLO");%>
请帮助
感谢
答案 0 :(得分:3)
尝试第二个:
我有一个看起来像这样的ajax请求:
$.ajax({
url: "/someplace",
dataType: "json",
async: true,
cache: false,
data: {
number0: 0,
key: littleKey
},
success: function(data, status)
{
alert(data);
}
});
它按预期工作。
您可以使用其他选项指定get type : "GET"
。
也许尝试让你的.jsp打印一些数据,无论如何,并打印它接收的数据。
答案 1 :(得分:0)
它在一个变量中,匿名函数中的数据变量传递给.done()
无论你需要gridedit.jsp返回的数据,最简单的方法就是在该函数中使用它。现在你正在做的就是制作一个包含返回数据的弹出窗口。