bht*_*oan 13 javascript jquery
我有一些继承代码的问题 - 它是一个类似FB的墙上应用程序,注册用户可以发布主题.很多代码都是JS和jQuery,我对它们知之甚少.
发布主题时,主题会添加到数据库中,但屏幕在刷新之前不显示主题,但应立即显示 - 当我查看开发人员工具时,我收到错误:
Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
Run Code Online (Sandbox Code Playgroud)
当我扩展错误时,我得到:
curCSS @ jquery-1.8.3.js:6825
jQuery.extend.css @ jquery-1.8.3.js:6782
isHidden @ jquery-1.8.3.js:6587
defaultPrefilter @ jquery-1.8.3.js:8797
Animation @ jquery-1.8.3.js:8697
doAnimation @ jquery-1.8.3.js:9034
jQuery.extend.dequeue @ jquery-1.8.3.js:1895
(anonymous function) @ jquery-1.8.3.js:1938
jQuery.extend.each @ jquery-1.8.3.js:611
jQuery.fn.jQuery.each @ jquery-1.8.3.js:241
jQuery.fn.extend.queue @ jquery-1.8.3.js:1931
jQuery.fn.extend.animate @ jquery-1.8.3.js:9044
jQuery.fn.(anonymous function) @ jquery-1.8.3.js:9129
(anonymous function) @ script.js:52
fire @ jquery-1.8.3.js:974
self.fireWith @ jquery-1.8.3.js:1084
done @ jquery-1.8.3.js:7803
callback @ jquery-1.8.3.js:8518
Run Code Online (Sandbox Code Playgroud)
script.js中的第52行是:
$('#loadpage').prepend($(response).fadeIn('slow'));
Run Code Online (Sandbox Code Playgroud)
我希望这不是jQuery 1.9.x及更高版本中修复的东西,因为升级会破坏太多东西以使其可行但我不知道从哪里开始对此进行故障排除
我发现有三个问题具有相同的错误,但是由于JS知识的问题,我无法从答案中得到任何想法.
取得了一些进展 - 我更新到jQUery 1.9.1,这次发生了同样的事情,但错误发生了变化.这次错误变成了:
Uncaught TypeError: Cannot set property 'cur' of undefined
Run Code Online (Sandbox Code Playgroud)
指向script.js中的同一行
快速搜索在jQuery 1.9中找到了带有fadeIn的Uncaught TypeError,建议更改该行:
$('#loadpage').prepend($(response).fadeIn('slow'));
Run Code Online (Sandbox Code Playgroud)
至:
$('#loadpage').prepend($(response).show());
Run Code Online (Sandbox Code Playgroud)
当我这样做时,不再有任何错误,但它仍然不能正常工作 - 当发布新帖子时,列表中添加了一个新条目,但它与之前的帖子重复.所以,例如,
Post 1
Post 2
Post 3
Run Code Online (Sandbox Code Playgroud)
如果我发布一个名为Post 4的新帖子,则显示为:
Post 1
Post 1
Post 2
Post 3
Run Code Online (Sandbox Code Playgroud)
当我刷新它然后正确显示为Post 4等所以感觉就像一些进步但仍然不完全存在
响应定义如下:
$('#post').click(function(){
var a = $("#wm").val();
if(a != "")
{
var keepID = $('#keepID').val();
var posted_on = $('#posted_on').val();
$.post("wall.php?value="+a+'&x='+keepID+'&p='+posted_on, {
}, function(response){
//console.log(response);
//$('#load').prepend($(response).fadeIn('slow'));
$('#load').prepend($(response).show());
$("#wm").val("");
});
}
});
Run Code Online (Sandbox Code Playgroud)
这个剧本很可怕!
您可能需要在显示元素之前插入该元素。尝试这个:
$('#post').click(function(){
var a = $("#wm").val();
if(a != "")
{
var keepID = $('#keepID').val();
var posted_on = $('#posted_on').val();
$.post("wall.php?value="+a+'&x='+keepID+'&p='+posted_on, {
}, function(response){
$(response).prependTo($('#load')).fadeIn('slow');
$("#wm").val("");
});
}
});
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,则php 脚本或您传递的 GET 参数中一定有错误