如何通过jQuery错误“$ not found error”?

时间:2009-12-10 03:04:33

标签: javascript jquery ajax

MAIN WINDOW

// some javascript
//some html
//here ajax-call to load all divs
//all divs hidden by default
//based on user choice(from select option), show selected group of divs
//click any shown div to call corresponding popup

POPUP WINDOW

//edit contents of that div.
//on close i need
1. refresh main window to load all divs
2. select the previously selected user option(from select option)
3. show corresponding divs only
4. most important is i have to give the user the main page,
   where they clicked the div before(not the page starting always!)

我试过,我留下了“$ not found error”。有任何想法吗..?建议?

这是主窗口

     <script type="text/javascript" src="jquerymin.js"></script>
        <script type="text/javascript">
        var visible_status=0;
        function selectFn(sno){
        if(sno==1){
                $('#id2').hide();
                $('#id1').show();
                visible_status=1;
        }else if(sno==2){
                $('#id2').show();
                $('#id1').show();
                visible_status=2;
        }
        }

        function popitup(url) {
            newwindow=window.open(url+'?parent_status='+visible_status,'name');
            if (window.focus) {newwindow.focus();}
                return false;
        }
        </script>
        <select name='optionw' 
        onchange="selectFn(this.options[this.selectedIndex].value);">
        <option value="">Select</option>
        <option value="1">Div1</option>
        <option value="2">All</option>
        </select>
        <div id='id1' style="display:none;">DIV1</div><!--by ajax i am loading-->
        <div id='id2' style="display:none;">DIV2</div><!--these divs-->
        <button onclick="popitup('popup.php');">popUp</button><br><!--and these-->

popupwindow

<script type="text/javascript" src="jquerymin.js"></script>
    <script type="text/javascript">
    var parent_status='<? echo $_GET[parent_status];?>';

    function closePopup() {
        window.opener.history.go(0);
        //alert('going to call parent selectFn('+parent_status+')');
        window.opener.selectFn(parent_status);
        self.close();
    }
    </script>

...Here  editing a part of the main page content...
<input type=button value=close_popup onclick="closePopup();">

如果我删除closePopup函数中的注释,它将按预期工作。任何有助于使其无需通信线路的帮助。

4 个答案:

答案 0 :(得分:2)

我建议您可能没有正确链接到jQuery库或者以错误的顺序链接它。你能提供一些关于你问的更多细节吗?您是否希望代码执行此操作,或者您只是询问未找到jQuery对象?

答案 1 :(得分:1)

为firefox获取firebug插件。加载您的页面..转到firebug控制台..键入$,如果它没有说'function()'你没有正确包含jQuery库

答案 2 :(得分:0)

我想了解你的问题;目前还不清楚你在描述什么。您加载后所显示的代码(通过查看源代码)是来自您的Web浏览器还是在服务器上进行评估之前?

如果在弹出窗口中更改此行,会发生什么:

var parent_status='<? echo $_GET[parent_status];?>';

到此:

var parent_status=1;

答案 3 :(得分:0)

根据我在此处理解的是下面的代码并检查它是否适合您:

将此代码粘贴到主窗口中:

<?php if(isset($_GET['parent_status'])): ?>
$(document).ready(function(){
    selectFn(<?php echo $_GET['parent_status'] ?>);
})
<?php endif ?>

在此代码下方:

function popitup(url) {
    newwindow=window.open(url+'?parent_status='+visible_status,'name');
    if (window.focus) {newwindow.focus();}
        return false;
}

然后,使用以下代码替换弹出窗口中的closePopup函数:

function closePopup() {
    var href = window.opener.location.href;
    if((pos = href.lastIndexOf('parent_status=')) >= 0)
    {
        var patt = new RegExp('parent_status=' + parent_status);
        href = href.replace(patt, 'parent_status='+parent_status);
    } else {
        href = window.opener.location.href + '?parent_status=' + parent_status
    }
    window.opener.location.href = href;
    self.close();
}

希望这有帮助。