我向我的控制器发送了一个AJAX请求.这个开发在JSP和Spring环境中完成. SimpleFormController被我正在使用的控制器覆盖.
使用JavaScript我创建对象并发送请求.此请求未传递给控制器.
发送请求的JavaScript代码.
function getStates(){
var httpRequest;
var country = document.getElementById('countryName');
alert(country);
var url = '/developer/register.htm';
url = url + (url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true');
if (window.ActiveXObject)
{
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
httpRequest = new XMLHttpRequest();
}
httpRequest.open("GET", url, true);
httpRequest.onreadystatechange = function() {processRequest(); };
httpRequest.send(null);
}
function processRequest() {
if(httpRequest.readyState == 4){
alert("inside ready state");
var response = http.responseText;
document.getElementById('states').innerHTML = response;
}
}
变量url以我在调度程序servlet中提到的方式给出.
浏览器在processRequest()函数中显示错误,告知未定义httpRequest.但是,我没有在前面的行中得到这个错误.我在getStates()函数中使用此对象.
解决方法:
这是因为变量httpRequest应该在getStates()函数之外定义.否则processRequest()无法看到它.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。