问题描述
有谁能告诉我如何将数据传递给进行AJAX调用的jsp?这就是我想要的:
Can anyone tell me how to pass data to the jsp making the AJAX call ? This is what I am trying:
这是我的AJAX电话:
Here is my AJAX call:
$.get("gridedit.jsp", { before: "row", time: "2pm" })
.done(function(data) {
alert("Data Loaded: " + data);
});
这是我的gridedit.jsp
here is my 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变量中。我该怎么做?
i want to store the value returned from gridedit.jsp into a javascript variable. How should I do this ?
请帮助
谢谢
编辑:
这里是我也尝试过的事情
here is what i also tried
$.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); }
});
我收到两条提醒,第一条提示
i get two alerts, the first one says
[object][object]
和第二个一说
error
任何人都可以知道最新情况吗?
can anyone figure out whats going on ?
请帮助
谢谢
错误;
所以我在这里尝试
$.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); }
});
我按顺序收到以下提醒:
i get the following alerts in order:
jqXHR:
[object] [object]
jqXHR: [object][object]
testStatus:
testStatus:
parseerror
errorthrown:
errorthrown:
Unexpected end of input
任何人都可以帮助我解决这个?我的gridedit.jsp执行此操作 - >
can anyone please help me in solving this ? my gridedit.jsp does this->
<%String b=request.getParameter("before");
System.out.println("b is here !" + b);
out.println("HELLO");%>
请帮助
谢谢
推荐答案
尝试第二个:
我有一个看起来像这样的ajax请求:
I have an ajax request that looks like this:
$.ajax({
url: "/someplace",
dataType: "json",
async: true,
cache: false,
data: {
number0: 0,
key: littleKey
},
success: function(data, status)
{
alert(data);
}
});
并按预期工作。
你可以用指定get:使用其他选项输入GET
。
也许尝试让你的.jsp打印一些数据,不管是什么,还打印它接收的数据。
Maybe try having your .jsp print some data no matter what, and also print what data it is receiving.
这篇关于如何将数据传递给AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!