Javascript $(document).ready中的语句(函数()不起作用
在Javascript $(document).ready中的语句(函数()不起作用,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,在$(文档)中有一个if语句未执行。该函数的所有其他组件都正常工作,但每次似乎都会失败。Firebug显示与文件相关的错误,设置断点后,Firebug短暂停止,然后将页面加载到100% 当登录按钮悬停在按钮上方并显示在按钮下方时,该语句将检索正确的HTML表单。请参见屏幕截图。一个显示在不同的.js文件中工作的完全相同的脚本,另一个显示它不工作,而是一个未定义的消息e出现。它们都在ready函数中的大量js文件中 $(document).ready函数有1600多行,问题函数位于底部。以下是语
$(文档)中有一个if语句
未执行。该函数的所有其他组件都正常工作,但每次似乎都会失败。Firebug
显示与文件相关的错误,设置断点后,Firebug
短暂停止,然后将页面加载到100%
当登录
按钮悬停在按钮上方并显示在按钮下方时,该语句将检索正确的HTML表单
。请参见屏幕截图。一个显示在不同的.js
文件中工作的完全相同的脚本,另一个显示它不工作,而是一个未定义的
消息e出现。它们都在ready
函数中的大量js
文件中
$(document).ready
函数有1600多行,问题函数位于底部。以下是语句:
var dropdown = document.getElementsByClassName("login-mega-main");
if (dropdown[0] != null){
$.ajax({
url: '/public/login/dropdown_login.jsp',
method: 'GET',
success: function(response) {
dropdown[0].innerHTML=response.responseText;
},
failure: function(response){
dropdown[0].innerHTML="<p>Failed to login. Please click 'Login' link</p>";
}
});
}
我猜括号被扔到了什么地方,但经过几个小时的搜索,我们什么也找不到。因为两页(截图)如果您使用相同的HTML
代码,我们真的不知所措。您得到的未定义
,因为响应。响应文本未定义。只需使用响应
var dropdown = document.getElementsByClassName("login-mega-main");
if (dropdown[0] != null){
$.ajax({
url: '/public/login/dropdown_login.jsp',
method: 'GET',
success: function(response) {
dropdown[0].innerHTML=response;
},
failure: function(response){
dropdown[0].innerHTML="<p>Failed to login. Please click 'Login' link</p>";
}
});
}
var dropdown=document.getElementsByClassName(“login-mega-main”);
如果(下拉列表[0]!=null){
$.ajax({
url:“/public/login/dropdown_login.jsp”,
方法:“GET”,
成功:功能(响应){
下拉列表[0]。innerHTML=响应;
},
故障:功能(响应){
下拉列表[0]。innerHTML=“登录失败。请单击“登录”链接”;
}
});
}
为了更好地理解jQuery您能用小提琴重现您的问题吗?更改下拉列表[0]。innerHTML=response.responseText;
->下拉列表[0]。innerHTML=response;
您能确认请求是使用Firebug发送的吗?:成功类型:函数(任何数据,字符串textStatus,jqXHR jqXHR)这似乎有效。为什么一个页面更喜欢resonse而不是response。responseText?@PT_C在这种情况下,它可能是XMLHttpRequest对象
,responseText
是该对象的属性
var dropdown = document.getElementsByClassName("login-mega-main");
if (dropdown[0] != null){
$.ajax({
url: '/public/login/dropdown_login.jsp',
method: 'GET',
success: function(response) {
dropdown[0].innerHTML=response;
},
failure: function(response){
dropdown[0].innerHTML="<p>Failed to login. Please click 'Login' link</p>";
}
});
}