未捕获的TypeError:对象#<object>没有方法'replace'第75行</object>

时间:2012-06-03 16:05:06

标签: jquery ajax

我正在组建一个锦标赛支架系统,让您可以拖动获胜者&#39;到下一轮,如果适用,输家将自动转移到他在失败者支架中的位置。每次下降后,我都会发送有关匹配的详细信息,以便进行个别跟踪,并在关闭和重新开启时重新填充位置。

我遇到了一个问题,我发送了一些不需要的字符,我使用.replace()摆脱了自己,现在获胜者方面的一切工作正常,但输家方面的任何事情都没有。希望有人可以帮助我找出原因。

15:   $(window).load(function(){
16:     $(".make-draggable, .draggable, .drag").draggable({
17:         helper: "clone",
18:         snap: ".draggable",
19:         snapMode: "inner"
20:     });
21:     $(".draggable").droppable({
22:         drop: function(event, ui) {
23:             var elemText = ui.draggable.text();
24:             $(this).html(elemText);
25:             var outB = ui.draggable.attr('id').split("-");
26:             var pl1;
27:             var pl2;
28:             if (outB[0] == "go") {
29:                 var num = outB.length;
30:                 var loser;
31:                 var loserval;
32:                 var losloc;
33:                 var losid = outB[1];
34:                 var numchars = outB[1].length;
35:                 if (num === 2) {
36:                     var i = 1;
37:                     loser = (losid.charAt(0) + "-");
38:                     pl1 = elemText;
39:                    for (i = 1; i < numchars; i++) {
40:                         loser = (loser+losid.charAt(i));
41:                     }
42:                     loserval = $("#go-" + loser);
43:                     losloc = ("#"+losid);
44:                     $(losloc).html(loserval.text());
45:                     pl2 = loserval.text();
46:                 } else if (num === 3) {
47:                     loser = (outB[1] + outB[2]);
48:                     loserval = $("#go-" + loser);
49:                     losloc = ("#"+loser);
50:                     $(losloc).html(loserval.text());
51:                     pl1 = loserval.text();
52:                     pl2 = elemText;
53:                 }
54:             } else {
55:               var getround = $(this).attr('id');
56:       if(getround == 'winner') {
57:           pl1 = $('#winnerb').text();
58:            pl2 = $('#loserb').text();
59:          } else {
60:            var inti = ui.draggable.attr('id').substring(1);
61:            if (inti%2 == 0) {
62:               var apl =  inti - 1;
63:               pl1 = elemText;
64:              pl2 = $('#l'+apl).text();
65:               alert(apl);
66:            } else {
67:               var apl =  inti++;
68:               alert(apl);
69:              pl1 = $('#l'+apl).text();
70:              pl2 = elemText;
71:            }
72:          }
73:             }
74:             var matrou = ui.draggable.parent().attr("id").split("-");
75:             $.urlParam = function(name){
76:                 var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
77:             return results[1] || 0;
78:             }
79:             pl1 = pl1.replace(/(\r\n|\n|\r)/gm,"");
80:             pl2 = pl2.replace(/(\r\n|\n|\r)/gm,"");
81:             elemText = elemText.replace(/(\r\n|\n|\r)/gm,"");
82:             var params = 'win='+elemText+'&p1='+pl1+'&p2='+pl2+'&match='+matrou[3]+'&round='+matrou[1]+'&wloc='+$(this).parent().attr('id')+'-'+$(this).attr('id')+'&lloc='+$(losloc).parent().attr('id')+'-'+$(loserval).attr('id')+'&tid='+$.urlParam('tid');
83:             xmlhttp=new XMLHttpRequest();
84:             xmlhttp.onreadystatechange=function() {
85:                 if (xmlhttp.readyState==4 && xmlhttp.status==200) {
86:                 }
87:             }
88:             xmlhttp.open("POST","sub_match.php",true);
89:             xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
90:             xmlhttp.setRequestHeader("Content-length", params.length);
91:             xmlhttp.setRequestHeader("Connection", "close");
92:             xmlhttp.send(params);            
93:         }
94:     });
95:   });

2 个答案:

答案 0 :(得分:1)

我在手机上,所以调试你的代码有点难,但我注意到在62行和66行中,你只是得到一个元素并将其分配给p1,而不是获取该元素的文本。尝试在该行的末尾添加.text()。

答案 1 :(得分:0)

我想在第62

  pl1 = $('l'+(inti+1));

应该是

  pl1 = $('l'+(inti+1)).text();

并排成一行66

pl2 = $('l'+(inti+1));

应该是

pl2 = $('l'+(inti+1)).text();