0

我目前正在使用 JQuery BBQ Js 插件对我的网站进行 ajaxified 导航,当我使用 ajax 导航整个网站时,有一个链接会显示此错误。

这是我的标记

<ul>
<li><a id="thankyou" href="#views/thankyou.jsp">Ajaxified Thank You Message</a></li>
<li><a id="register" href="#views/ajaxvalidation.jsp">Ajaxified Register Register</a></li>
<li><a id="register" href="#views/othermessage.jsp">Ajaxified Other Message</a></li>

</ul>

所有这两个链接都有效,但是当我单击第二个链接并提交表单时,当我单击其他锚标记时会显示此错误。

Uncaught TypeError: Object function (e,n){var r,i=[],s=function(e,t){t=v.isFunction(t)?t():t==null?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};n===t&&(n=v.ajaxSettings&&v.ajaxSettings.traditional);if(v.isArray(e)||e.jquery&&!v.isPlainObject(e))v.each(e,function(){s(this.name,this.value)});else for(r in e)fn(r,e[r],n,s);return i.join("&").replace(rn,"+")} has no method 'fragment' 

该错误是由该脚本触发的。

$(function(){
      var cache = {
        '': $('.bbq-default')
      };

      $(window).bind( 'hashchange', function(e) {

        var url = $.param.fragment();

        $( 'a.bbq-current' ).removeClass( 'bbq-current' );


        $( '.bbq-content' ).children( ':visible' ).hide();

        url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );

        if ( cache[ url ] ) {

          cache[ url ].show();

        } else {
          // Show "loading" content while AJAX content loads.
          $( '.bbq-loading' ).show();

          // Create container for this url's content and store a reference to it in
          // the cache.

          cache[ url ] = $( '<div class="bbq-item"/>' )

            .appendTo( '.bbq-content' )
            .load( url +"#content");//loads the content and get the div you want
        }
      })
      $(window).trigger( 'hashchange' );
    });

特别是这一行

 var url = $.param.fragment();

是什么导致了这个错误?

这也是第二个链接的样子..

<!DOCTYPE HTML>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#content').on('submit','#result',function(e){
        e.preventDefault();
        var data = $(this).serialize();
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "register.action", 
            type: "POST",  
            data: data,
            //Do not cache the page
            cache: false,
            //success
            success: function (html) {
               $('#content').html(html);       
            }       
        });
    })
})
</script>
</head>
<body>
    <h3>Simple Ajax Validation.</h3>
    <div id="divErrors"></div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <div id = "content">
    <s:form action="register" id="result">
        <label>UserName</label>
        <s:textfield name="userBean.username" />
        <s:fielderror />
        <input type ="submit" id = "result_0" value="AJAX Submit" />
    <!--  Test if Even Outside  the main page can access the other elements -->
    </s:form>  
    </div>
</body>
</html>
4

1 回答 1

0

我找到了解决方案,Jquery-bbq js 没有包含在 Ajaxvalidation.jsp 中,我所做的是我将 jquery-bbq.js 及其 AJAX 请求包含在另一个 JS 文件中,并且如果分别导入它们页面提出了请求

于 2012-12-26T10:06:57.383 回答