【发布时间】:2016-12-29 17:35:19
【问题描述】:
在进行 ajax 调用后,我正在使用 java 脚本来显示具有新 JS 内容的 div 中的数据。请参考以下代码:
//来自a.jsp的ajax调用
var goUrl = "/testMethod/getTestMethod;
var httpRequest=null;
var refreshContent = "null";
httpRequest = XMLHTTPObject();
httpRequest.open("POST", goUrl, true);
httpRequest.onreadystatechange = function () {ajaxFunction(refreshThisDiv,httpRequest); } ;
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
httpRequest.send(null);
function ajaxFunction(refreshThisDiv,httpRequest){
var serversideValidation = true;
if (httpRequest.readyState == 4)
{
if(httpRequest.status == 200)
{
results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
if(results != 'null') {
var test= document.getElementById(refreshThisdiv);
test.style.display = '' ;
test.innerHTML = results;
}
//下面是b.jsp中要显示的新内容。
<div id="test">
</div>
<script>
var test = document.getElementById("test");
test.innerHTML ="HI";
</script>
结果正常并重定向到 b.jsp 并显示 html 内容。但是标签不起作用:(
我想在该 div 的 ajax 调用完成后看到 Hi。请帮帮我。
【问题讨论】:
-
他们以什么方式“不工作”?您是否收到特定的错误消息?
-
-
脚本里有什么,请在
test.innerHTML = results;后面加上 -
@Vijay 非常感谢。我弄错了,你的建议成功了。
标签: javascript html ajax jsp