如何将数据传递给AJAX调用
谁能告诉我如何将数据传递给进行AJAX调用的jsp? 这就是我想要的:
这是我的AJAX电话:
$.get("gridedit.jsp", { before: "row", time: "2pm" }) .done(function(data) { alert("Data Loaded: " + data); });
这是我的gridedit.jsp
我想将从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这样做 – >
请帮忙
谢谢
尝试第二个:
我有一个看起来像这样的ajax请求:
$.ajax({ url: "/someplace", dataType: "json", async: true, cache: false, data: { number0: 0, key: littleKey }, success: function(data, status) { alert(data); } });
它按预期工作。
您可以使用其他选项指定get with type : "GET"
。
也许尝试让你的.jsp打印一些数据,无论如何,并打印它接收的数据。
它在一个变量中,匿名函数中的数据变量传递给.done()
无论你需要gridedit.jsp返回的数据,最简单的方法就是在该函数中使用它。 现在你正在做的就是制作一个包含返回数据的弹出窗口。