jQuery Ajax unt offiring对象的类型错误



我目前正在使用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>

我找到了解决方案,jquery-bbq js尚未包含在ajaxvalidation.jsp上,我所做的是,我包括了jquery-bbq.js及其ajax请求在另一个JS文件中,如果各个页面提出了请求

,则两者都将其导入

相关内容

  • 没有找到相关文章

最新更新