JQuery UI 1.8.10 Cannot read property '3'

2019-04-20 09:29发布

问题:

I use JQuery UI 1.8.10 and jquery latest.

My code is:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.js"></script>
<script type="text/javascript" src="/cms/ww.admin/login/login.js"></script>
</head>
<body>

<div id="header"></div>
<?php
    if(isset($_REQUEST['login_msg']))
    {
        require SCRIPTBASE.'cms/ww.incs/login-codes.php';
        $login_msg = $_REQUEST['login_msg'];
        if(isset($login_msg_codes[$login_msg]))
        {
            echo '<script>$(function(){$("<strong>'.htmlspecialchars($login_msg_codes[$login_msg]).'</strong>").dialog({modal:true});});</script>';
        }

?>

why does this give a cannot read property '3' of undefined error?

the file that gives the error is jquery-ui.js on line 186

okay now i changed it to:

</head>
<body>

<div id="header"></div>
<div id="login-msg"></div>
<?php
if(isset($_REQUEST['login_msg'])){
require SCRIPTBASE.'cms/ww.incs/login-codes.php';
$login_msg=$_REQUEST['login_msg'];
if(isset($login_msg_codes[$login_msg])){
   echo '<script>$(function(){
                    $("#login-msg").html("<strong>'.htmlspecialchars($login_msg_codes[$login_msg]).'</strong>").dialog({modal:true});});</script>';
}
}
 ?>

But still the same error

回答1:

It's a bug from your jQueryUI which use a :data selector (if you go up in the call stack you will see it) which is deprecated/not compatible with latest jQuery. Try with this jQueryUI :

http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.22/jquery-ui.min.js

example here :

http://jsfiddle.net/techunter/RyUVq/



回答2:

You found a bug/incompatibility!!

this isn't working jquery (1.8.0): http://jsfiddle.net/mZPWS/

Older jquery version (1.7.2) is working: http://jsfiddle.net/mZPWS/1/



回答3:

It might not be the source of your problem, but maybe setting a div for your .dialog() widget can help you.

Your js line $("<strong>'.htmlspecialchars($login_msg_codes[$login_msg]).'</strong>").dialog({modal:true} seems to be using a simple message, which in most cases works.

Can you try changing using this line instead :

$(function()
{
    $("#header") // or any div you have
    .html("<strong>'.htmlspecialchars($login_msg_codes[$login_msg]).'</strong>")
    .dialog({modal:true});
});

also, make sure your "/cms/ww.admin/login/login.js" is not the source of the error, the js error console gets easily lost and can point you to jquery-ui.js while the error is somewhere else.



回答4:

I confirm the uncompatibility issue. Tried with jquery-1.8.0 and jquery-ui-1.8.4