我有一个简单的 JS 函数,可以从浏览器中的 URL 检索一些数据。对该 JS 函数的调用是在 JSP 中进行的。 JS 函数是从 JSP 中的标记内调用的。
JS函数:
function parseURL(){
var info = "some value", // This is retrieved from the browser URL which is my.JSP
$.ajax({
method: post,
url: my.jsp // This is the same URL (browser URL) from which I am getting information, so I just send back to it
data: { information: info} )}
.done({
alert("Success");
})
});
}
当我尝试检索 JSP 中 scriplet 中的值时,它返回 null。我究竟做错了什么?任何帮助将不胜感激。谢谢。
最佳答案
我可以建议您按照以下步骤操作并找到适合您案例的方法!
首先在你的函数中
function parseURL(){
var info = "some value", // This is retrieved from the browser URL which is my.JSP
$.ajax({
method: post,
url: anotherPage.jsp // This is the same URL (browser URL) from which I am getting information, so I just send back to it
data: { information: info} )}
.done({
$("div or section where you want to inject the result").html(data);
})
});
}
并在 anotherPage.jsp 中尝试使用如下内容:
//jsp header 和内容以及您想要返回的数据,例如 scriplet 或表达式,只是前面的函数将注入(inject)的数据 如果您可以发布 my.jsp 和 anotherPage.jsp 可能会有所帮助
关于javascript - 使用AJAX将JS变量返回到JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37838220/